Skip to content

Commit

Permalink
Link service template ID and the DeployedService data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice1319 committed Mar 15, 2024
1 parent d5fca4e commit 5a21efc
Show file tree
Hide file tree
Showing 27 changed files with 610 additions and 5 deletions.
15 changes: 15 additions & 0 deletions modules/api/src/test/resources/ocl_terraform_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ flavors:
# Properties for the service, which can be used by the deployment.
properties:
flavor_id: s6.large.4
modificationImpact:
isDataLost: true
isServiceInterrupted: true
serviceProviderContactDetails:
email: [ "test@test.com" ]
deployment:
Expand All @@ -65,27 +68,39 @@ deployment:
minLength: 8
maxLength: 16
pattern: ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,16}$
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: vpc_name
description: The vpc name of the service instance. If the value is empty, will use the default value to find or create VPC.
kind: variable
dataType: string
example: "vpc-default"
mandatory: false
value: "vpc-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: subnet_name
description: The sub network name of the service instance. If the value is empty, will use the default value to find or create subnet.
kind: variable
dataType: string
example: "subnet-default"
mandatory: false
value: "subnet-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: secgroup_name
description: The security group name of the service instance. If the value is empty, will use the default value to find or create security group.
kind: variable
dataType: string
example: "secgroup-default"
mandatory: false
value: "secgroup-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
deployer: |
variable "flavor_id" {
type = string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ public class DeployVariable implements Serializable {

@Schema(description = "Variable autofill")
private AutoFill autoFill;

@NotNull
@Schema(description = "Variable modificationImpact")
private ModificationImpact modificationImpact;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public class Flavor extends FlavorBasic implements Serializable {
@Schema(description = "The properties of the flavor")
private Map<String, String> properties;

@NotNull
@Schema(description = "Impact on service when flavor is changed.")
private ModificationImpact modificationImpact;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

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

import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serial;
import java.io.Serializable;
import lombok.Data;

/**
* Defines for service ModificationImpact.
*/
@Data
public class ModificationImpact implements Serializable {

@Serial
private static final long serialVersionUID = -4160044806152791293L;

@Schema(description = "Is data lost when service configuration is modified.")
private Boolean isDataLost;

@Schema(description = "Is service availability interrupted when the configuration is "
+ "interrupted.")
private Boolean isServiceInterrupted;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DeployVariableTest {
private static final SensitiveScope sensitiveScope = SensitiveScope.ONCE;
private static DeployVariable deployVariable;
private static AutoFill autoFill = null;
private static ModificationImpact modificationImpact;

@BeforeEach
void setUp() {
Expand All @@ -46,6 +47,7 @@ void setUp() {
deployVariable.setValueSchema(validatorMap);
deployVariable.setSensitiveScope(sensitiveScope);
deployVariable.setAutoFill(autoFill);
deployVariable.setModificationImpact(modificationImpact);
}

@Test
Expand All @@ -59,6 +61,7 @@ void testGetterAndSetter() {
assertEquals(mandatory, deployVariable.getMandatory());
assertEquals(validatorMap, deployVariable.getValueSchema());
assertEquals(sensitiveScope, deployVariable.getSensitiveScope());
assertEquals(modificationImpact, deployVariable.getModificationImpact());
}

@Test
Expand Down Expand Up @@ -139,6 +142,12 @@ void testEqualsAndHashCode() {
assertNotEquals(deployVariable1, deployVariable2);
assertEquals(deployVariable.hashCode(), deployVariable1.hashCode());
assertNotEquals(deployVariable1.hashCode(), deployVariable2.hashCode());

deployVariable1.setModificationImpact(modificationImpact);
assertEquals(deployVariable, deployVariable1);
assertNotEquals(deployVariable1, deployVariable2);
assertEquals(deployVariable.hashCode(), deployVariable1.hashCode());
assertNotEquals(deployVariable1.hashCode(), deployVariable2.hashCode());
}

@Test
Expand All @@ -154,6 +163,7 @@ void testToString() {
", valueSchema=" + validatorMap + "" +
", sensitiveScope=" + sensitiveScope + "" +
", autoFill=" + autoFill + "" +
", modificationImpact=" + modificationImpact + "" +
")";
assertEquals(expectedString, deployVariable.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@ class FlavorTest {
private static final Integer fixedPrice = 1;
private static final Map<String, String> properties = Map.of("key", "value");
private static Flavor flavor;
private static ModificationImpact modificationImpact;

@BeforeEach
void setUp() {
flavor = new Flavor();
flavor.setName(name);
flavor.setFixedPrice(fixedPrice);
flavor.setProperties(properties);
flavor.setModificationImpact(modificationImpact);
}

@Test
void testGetterAndSetter() {
assertEquals(name, flavor.getName());
assertEquals(fixedPrice, flavor.getFixedPrice());
assertEquals(properties, flavor.getProperties());
assertEquals(modificationImpact, flavor.getModificationImpact());
}

@Test
Expand Down Expand Up @@ -74,14 +77,21 @@ void testEqualsAndHashCode() {
assertNotEquals(flavor1, flavor2);
assertEquals(flavor.hashCode(), flavor1.hashCode());
assertNotEquals(flavor1.hashCode(), flavor2.hashCode());

flavor1.setModificationImpact(modificationImpact);
assertEquals(flavor, flavor1);
assertNotEquals(flavor1, flavor2);
assertEquals(flavor.hashCode(), flavor1.hashCode());
assertNotEquals(flavor1.hashCode(), flavor2.hashCode());
}

@Test
void testToString() {
String expectedString = "Flavor(" +
"super=FlavorBasic(name=" + name +
", fixedPrice=" + fixedPrice + ")" +
", properties=" + properties + ")";
", properties=" + properties +
", modificationImpact=" + modificationImpact + ")";
assertEquals(expectedString, flavor.toString());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*
*/

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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Test of ModificationImpact.
*/
public class ModificationImpactTest {

private static final Boolean isDataLost = true;

private static final Boolean isServiceInterrupted = true;

private static ModificationImpact modificationImpact;

@BeforeEach
void setUp() {
modificationImpact = new ModificationImpact();
modificationImpact.setIsDataLost(isDataLost);
modificationImpact.setIsServiceInterrupted(isServiceInterrupted);
}

@Test
void testGetterAndSetter() {
assertEquals(isDataLost, modificationImpact.getIsDataLost());
assertEquals(isServiceInterrupted, modificationImpact.getIsServiceInterrupted());
}

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

Object obj = new Object();
assertNotEquals(modificationImpact, obj);
assertNotEquals(modificationImpact, null);
assertNotEquals(modificationImpact.hashCode(), obj.hashCode());

ModificationImpact modificationImpact1 = new ModificationImpact();
ModificationImpact modificationImpact2 = new ModificationImpact();
assertNotEquals(modificationImpact, modificationImpact1);
assertNotEquals(modificationImpact, modificationImpact2);
assertEquals(modificationImpact1, modificationImpact2);
assertNotEquals(modificationImpact.hashCode(), modificationImpact1.hashCode());
assertNotEquals(modificationImpact.hashCode(), modificationImpact2.hashCode());
assertEquals(modificationImpact1.hashCode(), modificationImpact2.hashCode());

modificationImpact1.setIsDataLost(isDataLost);
assertNotEquals(modificationImpact, modificationImpact1);
assertNotEquals(modificationImpact1, modificationImpact2);
assertNotEquals(modificationImpact.hashCode(), modificationImpact1.hashCode());
assertNotEquals(modificationImpact1.hashCode(), modificationImpact2.hashCode());

modificationImpact1.setIsServiceInterrupted(isServiceInterrupted);
assertEquals(modificationImpact, modificationImpact1);
assertNotEquals(modificationImpact1, modificationImpact2);
assertEquals(modificationImpact.hashCode(), modificationImpact1.hashCode());
assertNotEquals(modificationImpact1.hashCode(), modificationImpact2.hashCode());
}

@Test
void testToString() {
String expectedString = "ModificationImpact(" +
"isDataLost=" + isDataLost +
", isServiceInterrupted=" + isServiceInterrupted +
")";
assertEquals(expectedString, modificationImpact.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.xpanse.modules.models.response.Response;
import org.eclipse.xpanse.modules.models.response.ResultType;
import org.eclipse.xpanse.modules.models.servicetemplate.DeployVariable;
import org.eclipse.xpanse.modules.models.servicetemplate.ModificationImpact;
import org.eclipse.xpanse.modules.models.servicetemplate.Ocl;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.DeployVariableDataType;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.DeployVariableKind;
Expand Down Expand Up @@ -316,9 +317,9 @@ void testRegisterThrowsMethodArgumentNotValidException() throws Exception {
// Setup
Ocl ocl = oclLoader.getOcl(
URI.create("file:src/test/resources/ocl_terraform_test.yml").toURL());
ocl.setFlavors(null);
ocl.setBilling(null);
Response expectedResponse = Response.errorResponse(ResultType.UNPROCESSABLE_ENTITY,
Collections.singletonList("flavors:must not be null"));
Collections.singletonList("billing:must not be null"));
// Run the test
final MockHttpServletResponse response = register(ocl);
// Verify the results
Expand Down Expand Up @@ -355,6 +356,10 @@ void testRegisterThrowsInvalidValueSchemaException() throws Exception {
errorVariable.setName("errorVarName");
errorVariable.setDescription("description");
errorVariable.setExample("example");
ModificationImpact modificationImpact = new ModificationImpact();
modificationImpact.setIsDataLost(true);
modificationImpact.setIsServiceInterrupted(true);
errorVariable.setModificationImpact(modificationImpact);
String errorSchemaKey = "errorSchemaKey";
errorVariable.setValue("errorValue");
errorVariable.setValueSchema(Collections.singletonMap(errorSchemaKey, "errorSchemaValue"));
Expand Down
18 changes: 18 additions & 0 deletions runtime/src/test/resources/ocl_opentofu_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ flavors:
# Properties for the service, which can be used by the deployment.
properties:
flavor_id: s6.large.2
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: 2vCPUs-8GB-normal
# The fixed price during the period (the price applied one shot whatever is the service use)
fixedPrice: 30
# Properties for the service, which can be used by the deployment.
properties:
flavor_id: s6.large.4
modificationImpact:
isDataLost: true
isServiceInterrupted: true
serviceProviderContactDetails:
email: [ "test@test.com" ]
deployment:
Expand Down Expand Up @@ -70,27 +76,39 @@ deployment:
minLength: 8
maxLength: 16
pattern: ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,16}$
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: vpc_name
description: The vpc name of the service instance. If the value is empty, will use the default value to find or create VPC.
kind: variable
dataType: string
example: "vpc-default"
mandatory: false
value: "vpc-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: subnet_name
description: The sub network name of the service instance. If the value is empty, will use the default value to find or create subnet.
kind: variable
dataType: string
example: "subnet-default"
mandatory: false
value: "subnet-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: secgroup_name
description: The security group name of the service instance. If the value is empty, will use the default value to find or create security group.
kind: variable
dataType: string
example: "secgroup-default"
mandatory: false
value: "secgroup-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
deployer: |
variable "region" {
type = string
Expand Down

0 comments on commit 5a21efc

Please sign in to comment.