Skip to content

Commit

Permalink
block service hosting type update in template
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopar committed Nov 11, 2023
1 parent 8d6fb91 commit 0e8a2f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ public UUID deploy(@Valid @RequestBody DeployRequest deployRequest) {
Deployment deployment = this.deployService.getDeployHandler(deployTask);
this.deployService.asyncDeployService(deployment, deployTask);
String successMsg = String.format(
"Task for starting managed service %s-%s-%s started. UUID %s",
"Task for starting managed service %s-%s-%s-%s started. UUID %s",
deployRequest.getServiceName(),
deployRequest.getVersion(), deployRequest.getCsp(), deployTask.getId());
deployRequest.getVersion(),
deployRequest.getCsp().toValue(),
deployRequest.getServiceHostingType().toValue(),
deployTask.getId());
log.info(successMsg);
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,47 +80,51 @@ public ServiceTemplateEntity updateServiceTemplateByUrl(String id, String oclLoc
* @return Returns service template DB entity.
*/
public ServiceTemplateEntity updateServiceTemplate(String id, Ocl ocl) {
ServiceTemplateEntity existedService = storage.getServiceTemplateById(UUID.fromString(id));
if (Objects.isNull(existedService)) {
ServiceTemplateEntity existingService = storage.getServiceTemplateById(UUID.fromString(id));
if (Objects.isNull(existingService)) {
String errMsg = String.format("Service template with id %s not found.", id);
log.error(errMsg);
throw new ServiceTemplateNotRegistered(errMsg);
}
if (!StringUtils.equals(getUserNamespace(), existedService.getNamespace())) {
if (!StringUtils.equals(getUserNamespace(), existingService.getNamespace())) {
throw new AccessDeniedException("No permissions to update service templates "
+ "belonging to other namespaces.");
}
iconUpdate(existedService, ocl);
checkParams(existedService, ocl);
iconUpdate(existingService, ocl);
checkParams(existingService, ocl);
validateTerraformScript(ocl);
existedService.setOcl(ocl);
existedService.setServiceRegistrationState(ServiceRegistrationState.UPDATED);
existingService.setOcl(ocl);
existingService.setServiceRegistrationState(ServiceRegistrationState.UPDATED);
JsonObjectSchema jsonObjectSchema =
serviceVariablesJsonSchemaGenerator.buildJsonObjectSchema(
existedService.getOcl().getDeployment().getVariables());
existedService.setJsonObjectSchema(jsonObjectSchema);
storage.store(existedService);
serviceTemplateOpenApiGenerator.updateServiceApi(existedService);
return existedService;
existingService.getOcl().getDeployment().getVariables());
existingService.setJsonObjectSchema(jsonObjectSchema);
storage.store(existingService);
serviceTemplateOpenApiGenerator.updateServiceApi(existingService);
return existingService;
}

private void checkParams(ServiceTemplateEntity existedService, Ocl ocl) {
private void checkParams(ServiceTemplateEntity existingService, Ocl ocl) {

String oldCategory = existedService.getCategory().name();
String oldCategory = existingService.getCategory().name();
String newCategory = ocl.getCategory().name();
compare(oldCategory, newCategory, "category");

String oldName = existedService.getName();
String oldName = existingService.getName();
String newName = ocl.getName();
compare(oldName, newName, "service name");

String oldVersion = existedService.getVersion();
String oldVersion = existingService.getVersion();
String newVersion = ocl.getServiceVersion();
compare(oldVersion, newVersion, "service version");

String oldCsp = existedService.getCsp().name();
String oldCsp = existingService.getCsp().name();
String newCsp = ocl.getCloudServiceProvider().getName().name();
compare(oldCsp, newCsp, "csp");

String oldServiceHostingType = existingService.getServiceHostingType().toValue();
String newServiceHostingType = ocl.getServiceHostingType().toValue();
compare(oldServiceHostingType, newServiceHostingType, "service hosting type");
}

private void compare(String oldParams, String newParams, String type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void testUpdateServiceTemplateByUrl() throws Exception {
serviceTemplateEntity.setVersion(oclRegister.getServiceVersion());
serviceTemplateEntity.setCsp(oclRegister.getCloudServiceProvider().getName());
serviceTemplateEntity.setOcl(oclRegister);
serviceTemplateEntity.setServiceHostingType(oclRegister.getServiceHostingType());

when(mockOclLoader.getOcl(new URL(oclLocation))).thenReturn(ocl);
when(mockStorage.getServiceTemplateById(uuid)).thenReturn(serviceTemplateEntity);
Expand Down Expand Up @@ -161,6 +162,7 @@ void testUpdateServiceTemplate() throws Exception {
serviceTemplateEntity.setServiceRegistrationState(ServiceRegistrationState.REGISTERED);
serviceTemplateEntity.setVersion(oclRegister.getServiceVersion());
serviceTemplateEntity.setCsp(oclRegister.getCloudServiceProvider().getName());
serviceTemplateEntity.setServiceHostingType(oclRegister.getServiceHostingType());
serviceTemplateEntity.setOcl(oclRegister);

when(mockStorage.getServiceTemplateById(uuid)).thenReturn(serviceTemplateEntity);
Expand Down

0 comments on commit 0e8a2f9

Please sign in to comment.