Skip to content

Commit

Permalink
use constants in server poms & gradle build files
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcharl committed Aug 4, 2021
1 parent 6107855 commit e11846e
Show file tree
Hide file tree
Showing 32 changed files with 653 additions and 554 deletions.
1 change: 0 additions & 1 deletion generators/docker-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ function loadConfigs() {
const config = this.getJhipsterConfig(`${path}/.yo-rc.json`).getAll();
_.defaults(config, defaultConfig);
this.loadServerConfig(config);
this.loadDerivedServerConfig(config);
this.loadDerivedPlatformConfig(config);
this.loadDerivedAppConfig(config);

Expand Down
91 changes: 88 additions & 3 deletions generators/generator-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,26 @@ const NO_DATABASE = databaseTypes.NO;
const { GENERATOR_BOOTSTRAP } = require('./generator-list');
const { PROMETHEUS, ELK } = require('../jdl/jhipster/monitoring-types');
const { JWT, OAUTH2, SESSION } = require('../jdl/jhipster/authentication-types');
const { EHCACHE, REDIS, HAZELCAST, MEMCACHED } = require('../jdl/jhipster/cache-types');
const { CAFFEINE, EHCACHE, REDIS, HAZELCAST, INFINISPAN, MEMCACHED } = require('../jdl/jhipster/cache-types');
const { GRADLE, MAVEN } = require('../jdl/jhipster/build-tool-types');
const { SPRING_WEBSOCKET } = require('../jdl/jhipster/websocket-types');
const { KAFKA } = require('../jdl/jhipster/message-broker-types');
const { CONSUL, EUREKA } = require('../jdl/jhipster/service-discovery-types');
const { GATLING, CUCUMBER, PROTRACTOR, CYPRESS } = require('../jdl/jhipster/test-framework-types');
const { GATEWAY, MICROSERVICE, MONOLITH } = require('../jdl/jhipster/application-types');
const { ELASTICSEARCH } = require('../jdl/jhipster/search-engine-types');

const { getBase64Secret, getRandomHex } = require('./utils');
const cacheTypes = require('../jdl/jhipster/cache-types');
const serviceDiscoveryTypes = require('../jdl/jhipster/service-discovery-types');
const searchEngineTypes = require('../jdl/jhipster/search-engine-types');
const messageBrokerTypes = require('../jdl/jhipster/message-broker-types');
const websocketTypes = require('../jdl/jhipster/websocket-types');

const NO_CACHE = cacheTypes.NO;
const NO_SERVICE_DISCOVERY = serviceDiscoveryTypes.NO;
const NO_SEARCH_ENGINE = searchEngineTypes.FALSE;
const NO_MESSAGE_BROKER = messageBrokerTypes.NO;
const NO_WEBSOCKET = websocketTypes.FALSE;
// Reverse order.
const CUSTOM_PRIORITIES = [
{
Expand Down Expand Up @@ -2638,19 +2649,93 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
}

loadDerivedServerConfig(dest = this) {
if (!dest.packageFolder) {
dest.packageFolder = dest.packageName.replace(/\./g, '/');
}

// JWT authentication is mandatory with Eureka, so the JHipster Registry
// can control the applications
if (dest.serviceDiscoveryType === EUREKA && dest.authenticationType !== OAUTH2) {
dest.authenticationType = JWT;
}

// Generate JWT secret key if key does not already exist in config
if ((dest.authenticationType === JWT || dest.applicationType === MICROSERVICE) && dest.jwtSecretKey === undefined) {
dest.jwtSecretKey = getBase64Secret.call(this, null, 64);
}
// Generate remember me key if key does not already exist in config
if (dest.authenticationType === SESSION && !dest.rememberMeKey) {
dest.rememberMeKey = getRandomHex();
}

if (dest.authenticationType === OAUTH2) {
dest.skipUserManagement = true;
}

if (dest.enableHibernateCache && [NO_CACHE, MEMCACHED].includes(dest.cacheProvider)) {
this.info(`Disabling hibernate cache for cache provider ${dest.cacheProvider}`);
dest.enableHibernateCache = false;
}

// Convert to false for templates.
if (dest.serviceDiscoveryType === NO_SERVICE_DISCOVERY || !dest.serviceDiscoveryType) {
dest.serviceDiscoveryType = false;
}
if (dest.websocket === NO_WEBSOCKET || !dest.websocket) {
dest.websocket = false;
}
if (dest.searchEngine === NO_SEARCH_ENGINE || !dest.searchEngine) {
dest.searchEngine = false;
}
if (dest.messageBroker === NO_MESSAGE_BROKER || !dest.messageBroker) {
dest.messageBroker = false;
}

if (!dest.databaseType && dest.prodDatabaseType) {
dest.databaseType = this.getDBTypeFromDBValue(dest.prodDatabaseType);
}
if (!dest.devDatabaseType && dest.prodDatabaseType) {
dest.devDatabaseType = dest.prodDatabaseType;
}

// force variables unused by microservice applications
if (dest.applicationType === MICROSERVICE) {
dest.websocket = false;
}

const databaseType = dest.databaseType;
if (databaseType === NO_DATABASE) {
dest.devDatabaseType = NO_DATABASE;
dest.prodDatabaseType = NO_DATABASE;
dest.enableHibernateCache = false;
dest.skipUserManagement = true;
} else if ([MONGODB, NEO4J, COUCHBASE, CASSANDRA].includes(databaseType)) {
dest.devDatabaseType = databaseType;
dest.prodDatabaseType = databaseType;
dest.enableHibernateCache = false;
}
dest.buildToolGradle = dest.buildTool === GRADLE;
dest.buildToolMaven = dest.buildTool === MAVEN;
dest.buildToolUnknown = !dest.buildToolGradle && !dest.buildToolMaven;
dest.buildDir = this.getBuildDirectoryForBuildTool(dest.buildTool);

dest.cacheProviderRedis = dest.cacheProvider === REDIS;
dest.cacheProviderNo = dest.cacheProvider === NO_CACHE;
dest.cacheProviderCaffeine = dest.cacheProvider === CAFFEINE;
dest.cacheProviderEhCache = dest.cacheProvider === EHCACHE;
dest.cacheProviderHazelcast = dest.cacheProvider === HAZELCAST;
dest.cacheProviderInfinispan = dest.cacheProvider === INFINISPAN;
dest.cacheProviderMemcached = dest.cacheProvider === MEMCACHED;
dest.cacheProviderRedis = dest.cacheProvider === REDIS;

dest.devDatabaseTypeH2Disk = dest.devDatabaseType === H2_DISK;
dest.devDatabaseTypeH2Memory = dest.devDatabaseType === H2_MEMORY;
dest.devDatabaseTypeH2Any = dest.devDatabaseTypeH2Disk || dest.devDatabaseTypeH2Memory;
dest.devDatabaseTypeCouchbase = dest.devDatabaseType === COUCHBASE;
dest.devDatabaseTypeMariadb = dest.devDatabaseType === MARIADB;
dest.devDatabaseTypeMssql = dest.devDatabaseType === MSSQL;
dest.devDatabaseTypeMysql = dest.devDatabaseType === MYSQL;
dest.devDatabaseTypeOracle = dest.devDatabaseType === ORACLE;
dest.devDatabaseTypePostgres = dest.devDatabaseType === POSTGRESQL;

dest.prodDatabaseTypeCouchbase = dest.prodDatabaseType === COUCHBASE;
dest.prodDatabaseTypeH2Disk = dest.prodDatabaseType === H2_DISK;
Expand Down
4 changes: 2 additions & 2 deletions generators/languages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const prompts = require('./prompts');
const statistics = require('../statistics');
const constants = require('../generator-constants');
const { translationDefaultConfig } = require('../generator-defaults');
const { GENERATOR_LANGUAGES } = require('../generator-list');

const ANGULAR = constants.SUPPORTED_CLIENT_FRAMEWORKS.ANGULAR;
const REACT = constants.SUPPORTED_CLIENT_FRAMEWORKS.REACT;
Expand Down Expand Up @@ -182,7 +183,6 @@ module.exports = class extends BaseBlueprintGenerator {
this.loadDerivedClientConfig();
this.loadPlatformConfig();
this.loadServerConfig();
this.loadDerivedServerConfig();
this.loadTranslationConfig();
},
};
Expand Down Expand Up @@ -221,7 +221,7 @@ module.exports = class extends BaseBlueprintGenerator {
...super._missingPreDefault(),

insight() {
statistics.sendSubGenEvent('generator', 'languages');
statistics.sendSubGenEvent('generator', GENERATOR_LANGUAGES);
},
};
}
Expand Down
17 changes: 14 additions & 3 deletions generators/openshift/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const { KAFKA } = require('../../jdl/jhipster/message-broker-types');
const { PROMETHEUS } = require('../../jdl/jhipster/monitoring-types');
const { ELASTICSEARCH } = require('../../jdl/jhipster/search-engine-types');
const { GATEWAY, MONOLITH } = require('../../jdl/jhipster/application-types');
const { EUREKA } = require('../../jdl/jhipster/service-discovery-types');
const serviceDiscoveryTypes = require('../../jdl/jhipster/service-discovery-types');
const { StorageTypes } = require('../../jdl/jhipster/openshift-platform-types');
const databaseTypes = require('../../jdl/jhipster/database-types');
const writeFiles = require('./files').writeFiles;
const BaseDockerGenerator = require('../generator-base-docker');
Expand All @@ -32,6 +35,8 @@ const { setupKubernetesConstants } = require('../kubernetes-base');
const statistics = require('../statistics');

const NO_DATABASE = databaseTypes.NO;
const NO_SERVICE_DISCOVERY = serviceDiscoveryTypes.NO;
const { EPHEMERAL, PERSISTENT } = StorageTypes;

let useBlueprints;

Expand Down Expand Up @@ -158,6 +163,11 @@ module.exports = class extends BaseDockerGenerator {
return this._configuring();
}

_loadDerivedOpenshiftConfig(dest = this) {
dest.storageTypeEphemeral = dest.storageType === EPHEMERAL;
dest.storageTypePersistent = dest.storageType === PERSISTENT;
}

_loading() {
return {
loadSharedConfig() {
Expand All @@ -167,6 +177,7 @@ module.exports = class extends BaseDockerGenerator {
this.loadDerivedAppConfig(element);
});
this.loadDeploymentConfig(this);
this._loadDerivedOpenshiftConfig(this);
},
};
}
Expand Down Expand Up @@ -217,7 +228,7 @@ module.exports = class extends BaseDockerGenerator {
if (this.monitoring === PROMETHEUS) {
this.log(` ${chalk.cyan(`oc process -f ${this.directoryPath}ocp/monitoring/jhipster-metrics.yml | oc apply -f -`)}`);
}
if (this.useKafka === true) {
if (this.useKafka) {
this.log(` ${chalk.cyan(`oc process -f ${this.directoryPath}ocp/messagebroker/kafka.yml | oc apply -f -`)}`);
}
for (let i = 0, regIndex = 0; i < this.appsFolders.length; i++) {
Expand All @@ -226,9 +237,9 @@ module.exports = class extends BaseDockerGenerator {
if (app.searchEngine === ELASTICSEARCH) {
this.log(` ${chalk.cyan(`oc process -f ${this.directoryPath}ocp/${appName}/${appName}-elasticsearch.yml | oc apply -f -`)}`);
}
if (app.serviceDiscoveryType !== false && regIndex++ === 0) {
if (app.serviceDiscoveryType !== NO_SERVICE_DISCOVERY && regIndex++ === 0) {
this.log(` ${chalk.cyan(`oc process -f ${this.directoryPath}ocp/registry/application-configmap.yml | oc apply -f -`)}`);
if (app.serviceDiscoveryType === 'eureka') {
if (app.serviceDiscoveryType === EUREKA) {
this.log(` ${chalk.cyan(`oc process -f ${this.directoryPath}ocp/registry/jhipster-registry.yml | oc apply -f -`)}`);
} else {
this.log(` ${chalk.cyan(`oc process -f ${this.directoryPath}ocp/registry/consul.yml | oc apply -f -`)}`);
Expand Down
9 changes: 6 additions & 3 deletions generators/openshift/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const dockerPrompts = require('../docker-prompts');
const databaseTypes = require('../../jdl/jhipster/database-types');
const { ELASTICSEARCH } = require('../../jdl/jhipster/search-engine-types');
const { PROMETHEUS } = require('../../jdl/jhipster/monitoring-types');
const { StorageTypes } = require('../../jdl/jhipster/openshift-platform-types');

const { EPHEMERAL, PERSISTENT } = StorageTypes;

const NO_DATABASE = databaseTypes.NO;

Expand Down Expand Up @@ -69,15 +72,15 @@ async function askForStorageType() {
message: 'Which *type* of database storage would you like to use?',
choices: [
{
value: 'persistent',
value: PERSISTENT,
name: 'Persistent Storage',
},
{
value: 'ephemeral',
value: EPHEMERAL,
name: 'Ephemeral Storage',
},
],
default: 'ephemeral',
default: EPHEMERAL,
},
];

Expand Down
13 changes: 6 additions & 7 deletions generators/openshift/templates/db/cassandra.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ metadata:
namespace: <%= openshiftNamespace %>
annotations:
description: This template defines objects that are required to spin up a cassandra pod
tags: db, <%= app.baseName.toLowerCase() %>-cassandra<% if (storageType === 'persistent') { %> ,persistent <% } %> <% if (storageType === 'ephemeral') { %> ,ephemeral <% } %>
tags: db, <%= app.baseName.toLowerCase() %>-cassandra<% if (storageTypePersistent) { %> ,persistent <% } %> <% if (storageTypeEphemeral) { %> ,ephemeral <% } %>
openshift.io/display-name: <%= app.baseName.toLowerCase() %>-cassandra-template
openshift.io/long-description: >-
This template provides objects that are required to spin up a cassandra pod.<% if (storageType ==
'persistent') { %>The database is stored on persistent storage, so any restart of the service will not cause any impact to the data.
This template provides objects that are required to spin up a cassandra pod.<% if (storageTypePersistent) { %>The database is stored on persistent storage, so any restart of the service will not cause any impact to the data.
Please make sure you have provisioned PVs (Persistent Volumes) before using this template. <% } %>
<% if (storageType === 'ephemeral') { %>The database is not stored on persistent storage, so any restart of the service will result in all data being lost.<% } %>
<% if (storageTypeEphemeral) { %>The database is not stored on persistent storage, so any restart of the service will result in all data being lost.<% } %>
openshift.io/provider-display-name: JHipster-OpenShift
labels:
app: <%= app.baseName.toLowerCase() %>-cassandra
Expand All @@ -62,7 +61,7 @@ parameters:
required: true
displayName: "*** PLEASE DO NOT CHANGE THIS ***"
objects:
<%_ if (storageType === 'persistent') { _%>
<%_ if (storageTypePersistent) { _%>
-
apiVersion: <%= KUBERNETES_CORE_API_VERSION %>
kind: PersistentVolumeClaim
Expand Down Expand Up @@ -120,11 +119,11 @@ objects:
spec:
volumes:
- name: ${APPLICATION_NAME}-data
<%_ if (storageType === 'persistent') { _%>
<%_ if (storageTypePersistent) { _%>
persistentVolumeClaim:
claimName: ${APPLICATION_NAME}
<%_ } _%>
<%_ if (storageType === 'ephemeral') { _%>
<%_ if (storageTypeEphemeral) { _%>
emptyDir: {}
<%_ } _%>
containers:
Expand Down
17 changes: 8 additions & 9 deletions generators/openshift/templates/db/couchbase.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ metadata:
namespace: <%= openshiftNamespace %>
annotations:
description: This template defines objects that are required to spin up a couchbase pod
tags: db, <%= app.baseName.toLowerCase() %>-couchbase<% if (storageType === 'persistent') { %> ,persistent <% } %> <% if (storageType === 'ephemeral') { %> ,ephemeral <% } %>
tags: db, <%= app.baseName.toLowerCase() %>-couchbase<% if (storageTypePersistent) { %> ,persistent <% } %> <% if (storageTypeEphemeral) { %> ,ephemeral <% } %>
openshift.io/display-name: <%= app.baseName.toLowerCase() %>-couchbase-template
openshift.io/long-description: >-
This template provides objects that are required to spin up a couchbase pod.<% if (storageType ==
'persistent') { %>The database is stored on persistent storage, so any restart of the service will not cause any impact to the data.
This template provides objects that are required to spin up a couchbase pod.<% if (storageTypePersistent) { %>The database is stored on persistent storage, so any restart of the service will not cause any impact to the data.
Please make sure you have provisioned PVs (Persistent Volumes) before using this template. <% } %>
<% if (storageType === 'ephemeral') { %>The database is not stored on persistent storage, so any restart of the service will result in all data being lost.<% } %>
<% if (storageTypeEphemeral) { %>The database is not stored on persistent storage, so any restart of the service will result in all data being lost.<% } %>
openshift.io/provider-display-name: JHipster-OpenShift
labels:
app: <%= app.baseName.toLowerCase() %>-couchbase
Expand Down Expand Up @@ -91,7 +90,7 @@ objects:
stringData:
database-admin-user: "${COUCHBASE_ADMIN_USER}"
database-admin-password: "${COUCHBASE_ADMIN_PASSWORD}"
<%_ if (storageType === 'persistent') { _%>
<%_ if (storageTypePersistent) { _%>
-
apiVersion: <%= KUBERNETES_CORE_API_VERSION %>
kind: PersistentVolumeClaim
Expand Down Expand Up @@ -168,13 +167,13 @@ objects:
spec:
volumes:
- name: ${APPLICATION_NAME}-data
<%_ if (storageType === 'persistent') { _%>
<%_ if (storageTypePersistent) { _%>
persistentVolumeClaim:
claimName: ${APPLICATION_NAME}
<%_ } _%>
<%_ if (storageType === 'ephemeral') { _%>
<%_ } _%>
<%_ if (storageTypeEphemeral) { _%>
emptyDir: {}
<%_ } _%>
<%_ } _%>
containers:
- name: ${APPLICATION_NAME}
image: <%= DOCKER_COUCHBASE %>
Expand Down
13 changes: 6 additions & 7 deletions generators/openshift/templates/db/elasticsearch.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ metadata:
namespace: <%= openshiftNamespace %>
annotations:
description: This template defines objects that are required to spin up an elasticsearch pod
tags: elasticsearch, <%= app.baseName.toLowerCase() %>-elasticsearch<% if (storageType === 'persistent') { %> ,persistent <% } %> <% if (storageType === 'ephemeral') { %> ,ephemeral <% } %>
tags: elasticsearch, <%= app.baseName.toLowerCase() %>-elasticsearch<% if (storageTypePersistent) { %> ,persistent <% } %> <% if (storageTypeEphemeral) { %> ,ephemeral <% } %>
openshift.io/display-name: <%= app.baseName.toLowerCase() %>-elasticsearch-template
openshift.io/long-description: >-
This template provides objects that are required to spin up an elasticsearch pod.<% if (storageType ==
'persistent') { %>The database is stored on persistent storage, so any restart of the service will not cause any impact to the data.
This template provides objects that are required to spin up an elasticsearch pod.<% if (storageTypePersistent) { %>The database is stored on persistent storage, so any restart of the service will not cause any impact to the data.
Please make sure you have provisioned PVs (Persistent Volumes) before using this template. <% } %>
<% if (storageType === 'ephemeral') { %>The database is not stored on persistent storage, so any restart of the service will result in all data being lost.<% } %>
<% if (storageTypeEphemeral) { %>The database is not stored on persistent storage, so any restart of the service will result in all data being lost.<% } %>
openshift.io/provider-display-name: JHipster-OpenShift
labels:
app: <%= app.baseName.toLowerCase() %>-elasticsearch
Expand All @@ -54,7 +53,7 @@ parameters:
value: 1Gi
required: true
objects:
<%_ if (storageType === 'persistent') { _%>
<%_ if (storageTypePersistent) { _%>
-
apiVersion: <%= KUBERNETES_CORE_API_VERSION %>
kind: PersistentVolumeClaim
Expand Down Expand Up @@ -98,11 +97,11 @@ objects:
spec:
volumes:
- name: ${APPLICATION_NAME}-data
<%_ if (storageType === 'persistent') { _%>
<%_ if (storageTypePersistent) { _%>
persistentVolumeClaim:
claimName: ${APPLICATION_NAME}
<%_ } _%>
<%_ if (storageType === 'ephemeral') { _%>
<%_ if (storageTypeEphemeral) { _%>
emptyDir: {}
<%_ } _%>
containers:
Expand Down
Loading

0 comments on commit e11846e

Please sign in to comment.