Skip to content

Commit

Permalink
Merge pull request #369 from orange-cloudfoundry/feature-fix-deployme…
Browse files Browse the repository at this point in the history
…nt-dependencies-symlinks-copy

feature-fix-deployment-dependencies-symlinks-copy
  • Loading branch information
JCL38-ORANGE authored Feb 22, 2021
2 parents 24f1b05 + 4074f87 commit a5377c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void generate(Path workDir, String serviceInstanceId, CoabVarsFileDto coa
this.generateTemplateDirectory(workDir, serviceInstanceId);

//Generate deployment dependencies symlink
this.generateDeploymentDependenciesFileSymLink(workDir, serviceInstanceId);
this.generateDeploymentDependenciesFilesSymLink(workDir, serviceInstanceId);

//Generate coab vars file
this.generateCoabVarsFile(workDir, serviceInstanceId, coabVarsFileDto);
Expand Down Expand Up @@ -146,13 +146,18 @@ protected void generateTemplateDirectory(Path workDir, String serviceInstanceId)
DeploymentConstants.TEMPLATE);
}

protected void generateDeploymentDependenciesFileSymLink(Path workDir, String serviceInstanceId){
String[] sourcePathElements = new String[] {this.rootDeployment, this.modelDeployment};
String[] targetPathElements = new String[] {this.rootDeployment, this.computeDeploymentName(serviceInstanceId)};
String sourceFileName = DeploymentConstants.DEPLOYMENT_DEPENDENCIES_FILENAME;
StructureGeneratorHelper.generateSymbolicLink(workDir, sourcePathElements, targetPathElements, sourceFileName, sourceFileName);
protected void generateDeploymentDependenciesFilesSymLink(Path workDir, String serviceInstanceId){
List<String> pathList = this.searchForAllYmlFilesUnderModelDirectory(workDir);
for (String path: pathList) {
String[] sourcePathElements = new String[] {this.rootDeployment, this.modelDeployment};
String[] targetPathElements = new String[] {this.rootDeployment, this.computeDeploymentName(serviceInstanceId)};
StructureGeneratorHelper.generateSymbolicLink(workDir, sourcePathElements, targetPathElements, StructureGeneratorHelper.getFile(path), StructureGeneratorHelper.getFile(path));
}
}




public void generateCoabVarsFile(Path workDir, String serviceInstanceId, CoabVarsFileDto coabVarsFileDto){
String[] targetPathElements = new String[] {this.rootDeployment, this.computeDeploymentName(serviceInstanceId), DeploymentConstants.TEMPLATE};
String sourceFileName = DeploymentConstants.COAB + DeploymentConstants.HYPHEN + DeploymentConstants.VARS + DeploymentConstants.YML_EXTENSION;
Expand Down Expand Up @@ -203,6 +208,11 @@ protected void generateAllSymLinks(Path workDir, String serviceInstanceId){
}
}

protected List<String> searchForAllYmlFilesUnderModelDirectory(Path workDir){
Path path = StructureGeneratorHelper.generatePath(workDir, this.rootDeployment, this.modelDeployment);
return StructureGeneratorHelper.listFilesPaths(path, "glob:**/*.yml");
}

protected List<String> searchForAllFiles(Path workDir){
Path path = StructureGeneratorHelper.generatePath(workDir, this.rootDeployment, this.modelDeployment, DeploymentConstants.TEMPLATE);
return StructureGeneratorHelper.listFilesPaths(path, "glob:**/*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,44 @@ public void check_that_symlink_towards_coab_operators_file_is_generated() throws
}

@Test
public void check_that_symlink_towards_deployment_dependencies_file_is_generated() throws Exception {
public void check_that_symlink_towards_deployment_dependencies_file_are_generated() throws Exception {
//Given repository, root deployment,model deployment and operators directory with coab-operators file
Structure modelStructure = new Structure.StructureBuilder(this.workDir)
.withFile(new String[]{this.deploymentProperties.getRootDeployment(), this.deploymentProperties.getModelDeployment()},
DeploymentConstants.DEPLOYMENT_DEPENDENCIES_FILENAME)
.withFile(new String[]{this.deploymentProperties.getRootDeployment(), this.deploymentProperties.getModelDeployment()},
"deployment-dependencies-80-r2-vsphere.yml")
.build();
Structure deploymentStructure = new Structure.StructureBuilder(this.workDir)
.withDirectoryHierarchy(this.deploymentProperties.getRootDeployment(), this.templatesGenerator.computeDeploymentName(SERVICE_INSTANCE_ID))
.build();

//When
this.templatesGenerator.generateDeploymentDependenciesFileSymLink(this.workDir, SERVICE_INSTANCE_ID);
//this.templatesGenerator.generateDeploymentDependenciesFileSymLink(this.workDir, SERVICE_INSTANCE_ID);
this.templatesGenerator.generateDeploymentDependenciesFilesSymLink(this.workDir, SERVICE_INSTANCE_ID);

//Then
Path targetDeploymentDependenciesFile = StructureGeneratorHelper.generatePath(this.workDir,
this.deploymentProperties.getRootDeployment(),
this.templatesGenerator.computeDeploymentName(SERVICE_INSTANCE_ID),
DeploymentConstants.DEPLOYMENT_DEPENDENCIES_FILENAME);
Path targetDeploymentDependenciesAdditionalFile = StructureGeneratorHelper.generatePath(this.workDir,
this.deploymentProperties.getRootDeployment(),
this.templatesGenerator.computeDeploymentName(SERVICE_INSTANCE_ID),
"deployment-dependencies-80-r2-vsphere.yml");


assertThat("Symbolic link towards deployment dependencies file doesn't exist", Files.exists(targetDeploymentDependenciesFile));
assertThat("Deployment dependencies file is not a symbolic link", Files.isSymbolicLink(targetDeploymentDependenciesFile));
assertThat(Files.readSymbolicLink(targetDeploymentDependenciesFile).toString(), is(equalTo("../" + this.deploymentProperties.getModelDeployment() +
File.separator + DeploymentConstants.DEPLOYMENT_DEPENDENCIES_FILENAME)));
assertThat("Symbolic link towards additional deployment dependencies file doesn't exist", Files.exists(targetDeploymentDependenciesAdditionalFile));
assertThat("Deployment dependencies file is not a symbolic link", Files.isSymbolicLink(targetDeploymentDependenciesAdditionalFile));
assertThat(Files.readSymbolicLink(targetDeploymentDependenciesAdditionalFile).toString(), is(equalTo("../" + this.deploymentProperties.getModelDeployment() +
File.separator + "deployment-dependencies-80-r2-vsphere.yml")));



}

@Test
Expand Down Expand Up @@ -342,15 +358,15 @@ private String generatedStructure(String rootDeployment, String modelDeployment,
public void populateRealPaasTemplates() {

//Given a path
Path workDir = Paths.get("/home/losapio/GIT/Coab/paas-templates");
Path workDir = Paths.get("/data/GIT/FEInt/paas-templates-private-coab");

//Given and a user request
CoabVarsFileDto coabVarsFileDto = CoabVarsFileDtoSampleHelper.aTypicalUserProvisionningRequest();

//Given a template generator
TemplatesGenerator templatesGenerator = new TemplatesGenerator("coab-depls",
"cf-mysql",
"y",
"01-cf-mysql-extended",
"t",
"_",
new VarsFilesYmlFormatter());

Expand Down

0 comments on commit a5377c9

Please sign in to comment.