Skip to content

Commit

Permalink
add service hosting options
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopar committed Nov 7, 2023
1 parent cbfa387 commit 32c4441
Show file tree
Hide file tree
Showing 46 changed files with 215 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.api.config;

import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
* Bean for serializing string in request parameters to ServiceHostingType enum.
*/
@Component
public class ServiceHostingTypeEnumConverter implements Converter<String, ServiceHostingType> {

@Override
public ServiceHostingType convert(String serviceHostingType) {
return ServiceHostingType.getByValue(serviceHostingType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ private UserOrderableServiceVo convertToUserOrderableServiceVo(
userOrderableServiceVo.add(
WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(ServiceCatalogApi.class)
.openApi(serviceTemplateEntity.getId().toString())).withRel("openApi"));
userOrderableServiceVo.setServiceHostingType(
serviceTemplateEntity.getOcl().getServiceHostingType());
return userOrderableServiceVo;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ private ServiceTemplateDetailVo convertToServiceTemplateDetailVo(
serviceTemplateDetailVo.add(
WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(ServiceCatalogApi.class)
.openApi(serviceTemplateEntity.getId().toString())).withRel("openApi"));
serviceTemplateDetailVo.setServiceHostingType(
serviceTemplateEntity.getServiceHostingType());
return serviceTemplateDetailVo;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public ServiceTemplateEntity findServiceTemplate(
StringUtils.lowerCase(serviceTemplateEntity.getVersion())));
predicateList.add(criteriaBuilder.equal(root.get("category"),
serviceTemplateEntity.getCategory()));
predicateList.add(criteriaBuilder.equal(root.get("serviceHostingType"),
serviceTemplateEntity.getServiceHostingType()));
return query.where(criteriaBuilder.and(predicateList.toArray(new Predicate[0])))
.getRestriction();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.xpanse.modules.models.service.common.enums.Category;
import org.eclipse.xpanse.modules.models.service.common.enums.Csp;
import org.eclipse.xpanse.modules.models.servicetemplate.Ocl;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceRegistrationState;
import org.eclipse.xpanse.modules.models.servicetemplate.utils.JsonObjectSchema;
import org.hibernate.annotations.Type;
Expand All @@ -33,7 +34,8 @@
* Represents the SERVICE_TEMPLATE table in the database.
*/
@Table(name = "SERVICE_TEMPLATE", uniqueConstraints = {
@UniqueConstraint(columnNames = {"NAME", "VERSION", "CSP", "CATEGORY"})
@UniqueConstraint(columnNames = {
"NAME", "VERSION", "CSP", "CATEGORY", "SERVICE_HOSTING_TYPE"})
})
@Entity
@Data
Expand Down Expand Up @@ -62,6 +64,10 @@ public class ServiceTemplateEntity extends CreateModifiedTime {
@Column(name = "NAMESPACE")
private String namespace;

@Column(name = "SERVICE_HOSTING_TYPE")
@Enumerated(EnumType.STRING)
private ServiceHostingType serviceHostingType;

@Column(name = "OCL", columnDefinition = "json", nullable = false)
@Type(value = JsonType.class)
@Convert(converter = ObjectJsonConverter.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.UUID;
import org.eclipse.xpanse.modules.models.service.common.enums.Category;
import org.eclipse.xpanse.modules.models.service.common.enums.Csp;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;
import org.eclipse.xpanse.modules.models.servicetemplate.exceptions.ServiceTemplateNotRegistered;
import org.eclipse.xpanse.modules.models.servicetemplate.query.ServiceTemplateQueryModel;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -46,6 +47,7 @@ void testStore() {
serviceTemplateEntity.setVersion("version");
serviceTemplateEntity.setCsp(Csp.HUAWEI);
serviceTemplateEntity.setCategory(Category.AI);
serviceTemplateEntity.setServiceHostingType(ServiceHostingType.SERVICE_VENDOR);

// Run the test
test.store(serviceTemplateEntity);
Expand All @@ -58,6 +60,7 @@ void testStore() {
entity.setVersion("version");
entity.setCsp(Csp.HUAWEI);
entity.setCategory(Category.AI);
entity.setServiceHostingType(ServiceHostingType.SERVICE_VENDOR);
verify(mockServiceTemplateRepository).save(entity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void testToString() {
+ "csp=" + CSP + ", "
+ "category=" + CATEGORY + ", "
+ "namespace=test, "
+ "serviceHostingType=null" + ", "
+ "ocl=" + ocl + ", "
+ "serviceRegistrationState=" + SERVICE_STATE + ", "
+ "jsonObjectSchema=" + jsonObjectSchema + ")";
Expand All @@ -73,7 +74,6 @@ void testToString() {

@Test
void testEqualsAndHashCode() {
assertEquals(test, test);
assertEquals(test.hashCode(), test.hashCode());

Object o = new Object();
Expand Down
1 change: 1 addition & 0 deletions modules/database/src/test/resources/ocl_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cloudServiceProvider:
area: Asia China
- name: cn-north-4
area: Asia China
serviceHostingType: self
billing:
# The business model(`flat`, `exponential`, ...)
model: flat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public Deployment getDeployHandler(DeployTask deployTask) {
StringUtils.lowerCase(deployTask.getDeployRequest().getVersion()));
serviceTemplate.setCsp(deployTask.getDeployRequest().getCsp());
serviceTemplate.setCategory(deployTask.getDeployRequest().getCategory());
serviceTemplate.setServiceHostingType(
deployTask.getDeployRequest().getServiceHostingType());
serviceTemplate = serviceTemplateStorage.findServiceTemplate(serviceTemplate);
if (Objects.isNull(serviceTemplate) || Objects.isNull(serviceTemplate.getOcl())) {
throw new ServiceTemplateNotRegistered("Service template not found.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TerraformBootManager {
private TerraformApi terraformApi;
@Value("${spring.profiles.active}")
private String springProfilesActive;
@Value("${terraform.boot.endpoint=http://localhost:9090}")
@Value("${terraform.boot.endpoint:http://localhost:9090}")
private String terraformBootBaseUrl;

/**
Expand Down
1 change: 1 addition & 0 deletions modules/deployment/src/test/resources/ocl_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cloudServiceProvider:
area: Asia China
- name: cn-north-4
area: Asia China
serviceHostingType: self
billing:
# The business model(`flat`, `exponential`, ...)
model: flat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum Csp {
}

/**
* For CSP serialize.
* For CSP deserialize.
*/
@JsonCreator
public static Csp getByValue(String name) {
Expand All @@ -44,7 +44,7 @@ public static Csp getByValue(String name) {
}

/**
* For CSP deserialize.
* For CSP serialize.
*/
@JsonValue
public String toValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.xpanse.modules.models.service.common.enums.Category;
import org.eclipse.xpanse.modules.models.service.common.enums.Csp;
import org.eclipse.xpanse.modules.models.servicetemplate.Ocl;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;

/**
* Request body for service deployment.
Expand Down Expand Up @@ -83,6 +84,11 @@ public class DeployRequestBase implements Serializable {
@Schema(description = "The flavor of the Service.")
private String flavor;

@NotNull
@Schema(description = "Defines which cloud service account is used "
+ "for deploying cloud resources.")
private ServiceHostingType serviceHostingType;

@Hidden
private Ocl ocl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.models.common.exceptions.XpanseUnhandledException;
import org.eclipse.xpanse.modules.models.service.common.enums.Category;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;

/**
* Defines for OCLv2.
Expand Down Expand Up @@ -91,6 +92,12 @@ public class Ocl implements Serializable {
@Schema(description = "The billing policy of the managed service")
private Billing billing;

@Valid
@NotNull
@Schema(description = "Defines which cloud service account is used "
+ "for deploying cloud resources.")
private ServiceHostingType serviceHostingType;

/**
* an OCL object might be passed to different plugins for processing, in case any plugin want to
* change the property of Ocl, we should not change the original Object, we should change a deep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.modules.models.servicetemplate.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.xpanse.modules.models.common.exceptions.UnsupportedEnumValueException;

/**
* Defines which cloud service account is used for deploying cloud resources.
*/
@Schema(description = "Defines which cloud service account is used for deploying cloud resources.")
public enum ServiceHostingType {

SELF("self"),
SERVICE_VENDOR("service-vendor");

private final String serviceHostingType;

ServiceHostingType(String serviceHostingType) {
this.serviceHostingType = serviceHostingType;
}

/**
* For ServiceHostingType serialize.
*/
@JsonCreator
public static ServiceHostingType getByValue(String type) {
for (ServiceHostingType serviceHostingType : values()) {
if (serviceHostingType.toValue().equals(StringUtils.lowerCase(type))) {
return serviceHostingType;
}
}
throw new UnsupportedEnumValueException(
String.format("ServiceHostingType value %s is not supported.", type));
}

/**
* For ServiceHostingType deserialize.
*/
@JsonValue
public String toValue() {
return this.serviceHostingType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.xpanse.modules.models.servicetemplate.Deployment;
import org.eclipse.xpanse.modules.models.servicetemplate.Flavor;
import org.eclipse.xpanse.modules.models.servicetemplate.Region;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceRegistrationState;
import org.springframework.hateoas.RepresentationModel;

Expand Down Expand Up @@ -94,6 +95,12 @@ public class ServiceTemplateDetailVo extends RepresentationModel<ServiceTemplate
@Schema(description = "The billing policy of the registered service.")
private Billing billing;

@Valid
@NotNull
@Schema(description = "Defines which cloud service account is used "
+ "for deploying cloud resources.")
private ServiceHostingType serviceHostingType;

@NotNull
@Schema(description = "createTime of the registered service.")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss XXX")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.xpanse.modules.models.servicetemplate.DeployVariable;
import org.eclipse.xpanse.modules.models.servicetemplate.FlavorBasic;
import org.eclipse.xpanse.modules.models.servicetemplate.Region;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;
import org.springframework.hateoas.RepresentationModel;

/**
Expand Down Expand Up @@ -78,4 +79,10 @@ public class UserOrderableServiceVo extends RepresentationModel<UserOrderableSer
@Schema(description = "The billing policy of the orderable service.")
private Billing billing;

@Valid
@NotNull
@Schema(description = "Defines which cloud service account is used "
+ "for deploying cloud resources.")
private ServiceHostingType serviceHostingType;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.xpanse.modules.models.service.common.enums.Category;
import org.eclipse.xpanse.modules.models.service.common.enums.Csp;
import org.eclipse.xpanse.modules.models.servicetemplate.Ocl;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -166,6 +167,7 @@ void testToString() {
request.setCsp(csp);
request.setFlavor(flavor);
request.setOcl(ocl);
request.setServiceHostingType(ServiceHostingType.SERVICE_VENDOR);
request.setServiceRequestProperties(properties);

String expectedToString = "DeployRequest(super=DeployRequestBase(" +
Expand All @@ -177,6 +179,7 @@ void testToString() {
", region=" + region +
", csp=" + csp +
", flavor=" + flavor +
", serviceHostingType=" + ServiceHostingType.SERVICE_VENDOR +
", ocl=" + ocl +
", serviceRequestProperties=" + properties +
"), id=" + id + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void testHashCode() {
void testToString() {
String result = "MigrateRequest(super=DeployRequestBase(userId=null, category=null, "
+ "serviceName=null, customerServiceName=null, version=null, region=null, csp=null,"
+ " flavor=null, ocl=null, serviceRequestProperties=null), id=null)";
+ " flavor=null, serviceHostingType=null, ocl=null, serviceRequestProperties=null), id=null)";
assertThat(migrateRequestUnderTest.toString()).isEqualTo(result);
}
}

0 comments on commit 32c4441

Please sign in to comment.