Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ DBB_MODELER_APPMAPPINGS_DIR="$DBB_MODELER_WORK/config/applications-mappings"
# Reference to the repository paths mapping file
REPOSITORY_PATH_MAPPING_FILE=$DBB_MODELER_WORK/config/repositoryPathsMapping.yaml
# Reference to the type mapping file
APPLICATION_MEMBER_TYPE_MAPPING=$DBB_MODELER_WORK/config/types/types.txt
APPLICATION_FILES_TYPES_MAPPING=$DBB_MODELER_WORK/config/types/filesToTypesMapping.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the applicationsMapping.yaml, should the default file name be probably typesMapping.yaml. This would also fit with the typesConfiguration.yaml file.

# Reference to the type configuration file to generate build configuration
TYPE_CONFIGURATIONS_FILE=$DBB_MODELER_WORK/config/types/typesConfigurations.yaml
# Input files and configuration
Expand Down Expand Up @@ -148,7 +148,7 @@ PIPELINE_CI=

# Arrays for configuration parameters, that will the Setup script will prompt the user for
path_config_array=(DBB_MODELER_APPCONFIG_DIR DBB_MODELER_APPLICATION_DIR DBB_MODELER_LOGS DBB_MODELER_DEFAULT_APP_REPO_CONFIG)
input_array=(DBB_MODELER_APPMAPPINGS_DIR REPOSITORY_PATH_MAPPING_FILE APPLICATION_MEMBER_TYPE_MAPPING TYPE_CONFIGURATIONS_FILE APPLICATION_ARTIFACTS_HLQ SCAN_CONTROL_TRANSFERS SCAN_DATASET_MEMBERS SCAN_DATASET_MEMBERS_ENCODING DBB_ZAPPBUILD DBB_COMMUNITY_REPO APPLICATION_DEFAULT_BRANCH PUBLISH_ARTIFACTS INTERACTIVE_RUN)
input_array=(DBB_MODELER_APPMAPPINGS_DIR REPOSITORY_PATH_MAPPING_FILE APPLICATION_FILES_TYPES_MAPPING TYPE_CONFIGURATIONS_FILE APPLICATION_ARTIFACTS_HLQ SCAN_CONTROL_TRANSFERS SCAN_DATASET_MEMBERS SCAN_DATASET_MEMBERS_ENCODING DBB_ZAPPBUILD DBB_COMMUNITY_REPO APPLICATION_DEFAULT_BRANCH PUBLISH_ARTIFACTS INTERACTIVE_RUN)
# Publishing options that are conditionally prompted, if PUBLISH_ARTIFACTS=true
publishing_options=(ARTIFACT_REPOSITORY_SERVER_URL ARTIFACT_REPOSITORY_USER ARTIFACT_REPOSITORY_PASSWORD ARTIFACT_REPOSITORY_SUFFIX PIPELINE_USER PIPELINE_USER_GROUP)

Expand Down
19 changes: 19 additions & 0 deletions samples/filesToTypesMapping.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
files:
- file: "DBEHM.MIG.COBOL(LGACDB01)"
types:
- "CBLCICSDB2"
properties:
- name: "COBPARM"
value: "AMODE(31)"
- file: "DBEHM.MIG.COBOL(LGACDB02)"
types:
- "CBLDB2"
properties:
- name: "COBPARM"
value: "AMODE(31)"
- file: "DBEHM.MIG.COBOL(LGACUS01)"
types:
- "CBLCICS"
properties:
- name: "COBPARM"
value: "AMODE(31)"
22 changes: 9 additions & 13 deletions src/groovy/extractApplications.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ unassignedApplicationMappingConfiguration.application = "UNASSIGNED"
@Field HashSet<String> filteredApplications = new HashSet<String>()

// Types Configurations
@Field HashMap<String, String> types
@Field ArrayList filesToTypesMapping
// script properties
@Field Properties props = new Properties()
@Field repositoryPathsMapping
Expand Down Expand Up @@ -100,13 +100,9 @@ if (props.REPOSITORY_PATH_MAPPING_FILE) {

// Read the Types from file
logger.logMessage("** Reading the Type Mapping definition.")
if (props.APPLICATION_MEMBER_TYPE_MAPPING) {
def typesFile = new File(props.APPLICATION_MEMBER_TYPE_MAPPING)
if (!typesFile.exists()) {
logger.logMessage("*! [WARNING] File ${props.APPLICATION_MEMBER_TYPE_MAPPING} not found in the current working directory. All artifacts will use the 'UNKNOWN' type.")
} else {
types = fileUtils.loadTypes(props.APPLICATION_MEMBER_TYPE_MAPPING)
}
if (props.APPLICATION_FILES_TYPES_MAPPING) {
filesToTypesMapping = fileUtils.loadFilesToTypesMapping(props.APPLICATION_FILES_TYPES_MAPPING)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the need to externalise the loadFilesToTypesMapping() method into the utilities. It is only invoked once. Can't we keep it inside of the extractApplications.groovy script?

println(filesToTypesMapping)
} else {
logger.logMessage("*! [WARNING] No Types File provided. The 'UNKNOWN' type will be assigned by default to all artifacts.")
}
Expand Down Expand Up @@ -286,12 +282,12 @@ def parseArgs(String[] args) {
System.exit(1)
}

if (configuration.APPLICATION_MEMBER_TYPE_MAPPING) {
File file = new File(configuration.APPLICATION_MEMBER_TYPE_MAPPING)
if (configuration.APPLICATION_FILES_TYPES_MAPPING) {
File file = new File(configuration.APPLICATION_FILES_TYPES_MAPPING)
if (file.exists()) {
props.APPLICATION_MEMBER_TYPE_MAPPING = configuration.APPLICATION_MEMBER_TYPE_MAPPING
props.APPLICATION_FILES_TYPES_MAPPING = configuration.APPLICATION_FILES_TYPES_MAPPING
} else {
logger.logMessage("*! [ERROR] The Types file '${configuration.APPLICATION_MEMBER_TYPE_MAPPING}' does not exist. Exiting.")
logger.logMessage("*! [ERROR] The Types file '${configuration.APPLICATION_FILES_TYPES_MAPPING}' does not exist. Exiting.")
System.exit(1)
}
}
Expand Down Expand Up @@ -393,7 +389,7 @@ def generateApplicationFiles(ApplicationMappingConfiguration applicationConfigur
(scannedLanguage, scannedFileType) = scanDatasetMember(constructDatasetForZFileOperation(dataset, member))
}
def lastQualifier = getLastQualifier(dataset)
def memberType = fileUtils.getType(types, member.toUpperCase())
def memberType = fileUtils.getType(filesToTypesMapping, datasetMember)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the need to externalise the getType() method. It is only invoked once. Can't we keep it inside of the extractApplications.groovy script?

// Identifying the matching Repository Path
// based on 1) the scan result if enabled
// 2) the type if set
Expand Down
36 changes: 13 additions & 23 deletions src/groovy/utils/fileUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,26 @@ import groovy.cli.commons.*


// Reads a HashMap from the MEMBER_TYPE_MAPPING file with comma separator (',') and returns it
def loadTypes(String APPLICATION_MEMBER_TYPE_MAPPING) {
HashMap<String, String> types = new HashMap<>();
String line;
File applicationMemberTypeMappingFile = new File(APPLICATION_MEMBER_TYPE_MAPPING)
if (!applicationMemberTypeMappingFile.exists()) {
logger.logMessage("*! [WARNING] The Application Member Type Mapping file $APPLICATION_MEMBER_TYPE_MAPPING was not found. Exiting.")
System.exit(1)
def loadFilesToTypesMapping(String APPLICATION_FILES_TYPES_MAPPING) {
File filesToTypeMappingFile = new File(APPLICATION_FILES_TYPES_MAPPING)
if (!filesToTypeMappingFile.exists()) {
logger.logMessage("*! [WARNING] The Files to Types Mapping file '$APPLICATION_FILES_TYPES_MAPPING' was not found. Exiting.")
return null
} else {
def yamlSlurper = new groovy.yaml.YamlSlurper()
applicationMemberTypeMappingFile.withReader("UTF-8") { reader ->
while ((line = reader.readLine()) != null) {
String[] keyValuePair = line.split(",", 2);
if (keyValuePair.length > 1) {
String key = keyValuePair[0].trim().toUpperCase();
String value = keyValuePair[1].trim().replaceAll(" ", "");
types.put(key, value);
}
}
}
return yamlSlurper.parse(filesToTypeMappingFile).files
}
return types
}

def getType(HashMap<String, String> types, String member) {
if (!types) {
def getType(ArrayList filesToTypes, String file) {
if (!filesToTypes) {
return "UNKNOWN"
} else {
def type = types.get(member)
if (type) {
return type
def foundFile = filesToTypes.find { fileToTypes ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variable name "foundFile" is confusing. It's the list of types for the provided dataset(member)

fileToTypes.file.equalsIgnoreCase(file)
}
if (foundFile) {
return foundFile.types.toString().replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(" ", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep the idea of allowing multiple types ... could we consider of sorting the list? And instead of replaceAll() a better way would be to join them

} else {
return "UNKNOWN"
}
Expand Down
10 changes: 5 additions & 5 deletions src/scripts/utils/0-validateConfiguration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ initializeWorkDirectory() {
fi
fi
if [ $rc -eq 0 ]; then
echo " [INFO] Copying sample Repository Paths mapping file to '$REPOSITORY_PATH_MAPPING_FILE'"
echo " [INFO] Copying sample Repository Paths Mapping file to '$REPOSITORY_PATH_MAPPING_FILE'"
mkdir -p "$(dirname $REPOSITORY_PATH_MAPPING_FILE)"
cp $DBB_MODELER_HOME/samples/repositoryPathsMapping.yaml $REPOSITORY_PATH_MAPPING_FILE
command_rc=$?
Expand All @@ -265,13 +265,13 @@ initializeWorkDirectory() {
fi
fi
if [ $rc -eq 0 ]; then
echo " [INFO] Copying sample Types file to '$APPLICATION_MEMBER_TYPE_MAPPING'"
mkdir -p "$(dirname $APPLICATION_MEMBER_TYPE_MAPPING)"
cp $DBB_MODELER_HOME/samples/types.txt $APPLICATION_MEMBER_TYPE_MAPPING
echo " [INFO] Copying sample Files to Types Mapping file to '$APPLICATION_FILES_TYPES_MAPPING'"
mkdir -p "$(dirname $APPLICATION_FILES_TYPES_MAPPING)"
cp $DBB_MODELER_HOME/samples/filesToTypesMapping.yaml $APPLICATION_FILES_TYPES_MAPPING
command_rc=$?
if [ $command_rc -ne 0 ]; then
rc=8
ERRMSG="[ERROR] Unable to copy sample Types file to '$APPLICATION_MEMBER_TYPE_MAPPING'."
ERRMSG="[ERROR] Unable to copy sample Files to Types Mapping file to '$APPLICATION_FILES_TYPES_MAPPING'."
echo $ERRMSG
fi
fi
Expand Down