Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use constants in server poms & gradle build files #15846

Merged
merged 5 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions generators/docker-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ function loadConfigs() {
if (this.fs.exists(`${path}/.yo-rc.json`)) {
const config = this.getJhipsterConfig(`${path}/.yo-rc.json`).getAll();
_.defaults(config, defaultConfig);
this.loadServerConfig(config);
this.loadDerivedServerConfig(config);
this.loadServerConfig(config, config);
this.loadDerivedPlatformConfig(config);
this.loadDerivedAppConfig(config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,24 @@ _%>
<%_ } _%>
}
: {
<%_ for (field of fields.filter(field => !field.id)) {
const fieldName = field.fieldName;
if (field.fieldIsEnum) {
const enumValues = field.enumValues;_%>
<%= fieldName %>: '<%= enumValues[0].name %>',
<%_ } _%>
mshima marked this conversation as resolved.
Show resolved Hide resolved
...<%= entityInstance %>Entity,
<%_ for (field of fields.filter(field => !field.id)) {
const fieldType = field.fieldType;
const fieldName = field.fieldName;
const fieldNameHumanized = field.fieldNameHumanized;

if (field.fieldTypeTimed) { _%>
if (field.fieldTypeTimed) { _%>
<%= fieldName %>: convertDateTimeFromServer(<%= entityInstance %>Entity.<%= fieldName %>),
<%_ } else if (field.fieldIsEnum) {
const enumValues = field.enumValues;
_%>
<%= fieldName %>: '<%= enumValues[0].name %>',
<%_ } _%>
<%_ } _%>
<%_ relationships.forEach(rel => {
const otherEntityPkName = rel.otherEntity.primaryKey && rel.otherEntity.primaryKey.name || 'id';
const relationshipFieldName = rel.relationshipFieldName;
const relationshipFieldNamePlural = rel.relationshipFieldNamePlural;
if (rel.relationshipManyToOne || (rel.relationshipOneToOne && rel.ownerSide)) { _%>
if (rel.relationshipManyToOne || (rel.relationshipOneToOne && rel.ownerSide)) { _%>
<%= relationshipFieldName %>Id: <%= entityInstance %>Entity?.<%= relationshipFieldName %>?.id,
<%_ } else if (rel.relationshipManyToMany && rel.ownerSide) { _%>
<%= relationshipFieldNamePlural %>: <%= entityInstance %>Entity?.<%= relationshipFieldNamePlural %>?.map(e => e.<%= otherEntityPkName %>.toString()),
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 @@ -167,6 +172,7 @@ module.exports = class extends BaseDockerGenerator {
this.loadDerivedAppConfig(element);
});
this.loadDeploymentConfig(this);
this._loadDerivedOpenshiftConfig(this);
},
};
}
Expand Down Expand Up @@ -217,7 +223,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 +232,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 Expand Up @@ -259,4 +265,9 @@ module.exports = class extends BaseDockerGenerator {
if (useBlueprints) return;
return this._end();
}

_loadDerivedOpenshiftConfig(dest = this) {
dest.storageTypeEphemeral = dest.storageType === EPHEMERAL;
dest.storageTypePersistent = dest.storageType === PERSISTENT;
}
};
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
Loading