-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend OCL to provide auto-fill for deploy variables
- Loading branch information
1 parent
af6b0eb
commit 9c7a9fe
Showing
10 changed files
with
1,311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
modules/models/src/main/java/org/eclipse/xpanse/modules/models/servicetemplate/AutoFill.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 jakarta.validation.constraints.NotNull; | ||
import lombok.Data; | ||
import org.eclipse.xpanse.modules.models.service.deploy.enums.DeployResourceKind; | ||
|
||
/** | ||
* Define autofill properties for deployment variables. | ||
*/ | ||
@Data | ||
public class AutoFill { | ||
|
||
@NotNull | ||
@Schema(description = "Type of the cloud resource to be reused.") | ||
private DeployResourceKind deployResourceKind; | ||
|
||
@NotNull | ||
@Schema(description = " defines if the required cloud resource can be newly created " | ||
+ "or should the existing resources must only be used.") | ||
private Boolean isAllowCreate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ava/org/eclipse/xpanse/modules/servicetemplate/utils/DeployVariableAutoFillValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
* | ||
*/ | ||
|
||
package org.eclipse.xpanse.modules.servicetemplate.utils; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.eclipse.xpanse.modules.models.response.ResultType; | ||
import org.eclipse.xpanse.modules.models.service.deploy.enums.DeployResourceKind; | ||
import org.eclipse.xpanse.modules.models.servicetemplate.DeployVariable; | ||
import org.eclipse.xpanse.modules.models.servicetemplate.exceptions.InvalidValueSchemaException; | ||
|
||
/** | ||
* Deployment variables automatically fill in the verification class. | ||
*/ | ||
@Slf4j | ||
public class DeployVariableAutoFillValidator { | ||
|
||
/** | ||
* Define a method to verify automatic filling of deployment variables. | ||
* | ||
* @param deployVariables deployVariables. | ||
*/ | ||
public static void validateDeployVariableAutoFill(List<DeployVariable> deployVariables) { | ||
if (!hasAutoFillAndParentKind(deployVariables)) { | ||
log.error("variable schema definition invalid"); | ||
throw new InvalidValueSchemaException( | ||
List.of(ResultType.VARIABLE_SCHEMA_DEFINITION_INVALID.toValue())); | ||
} | ||
return; | ||
} | ||
|
||
private static boolean hasAutoFillAndParentKind(List<DeployVariable> deployVariables) { | ||
for (DeployVariable deployVariable : deployVariables) { | ||
if (Objects.nonNull(deployVariable.getAutoFill())) { | ||
DeployResourceKind currentResourceKind = | ||
deployVariable.getAutoFill().getDeployResourceKind(); | ||
DeployResourceKind parentKind = currentResourceKind.getParent(); | ||
if (Objects.nonNull(parentKind)) { | ||
for (DeployVariable otherVariable : deployVariables) { | ||
if (otherVariable != deployVariable | ||
&& Objects.nonNull(otherVariable.getAutoFill()) | ||
&& otherVariable.getAutoFill().getDeployResourceKind() | ||
== parentKind) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.