import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;
import org.onap.clamp.clds.sdc.controller.installer.MicroService;
import org.onap.clamp.clds.util.JsonUtils;
+import org.onap.clamp.clds.util.drawing.SvgFacade;
import org.onap.clamp.policy.Policy;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
@Autowired
DcaeInventoryServices dcaeInventoryService;
+ @Autowired
+ private SvgFacade svgFacade;
+
@Override
public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException {
boolean alreadyInstalled = true;
blueprintArtifact.getResourceAttached().getResourceInstanceName(),
blueprintArtifact.getBlueprintArtifactName()));
newLoop.setLastComputedState(LoopState.DESIGN);
- newLoop.setMicroServicePolicies(createMicroServicePolicies(csar, blueprintArtifact, newLoop));
+
+ List<MicroService> microServicesChain = chainGenerator
+ .getChainOfMicroServices(blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint()));
+ if (microServicesChain.isEmpty()) {
+ microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint());
+ }
+
+ newLoop
+ .setMicroServicePolicies(createMicroServicePolicies(microServicesChain, csar, blueprintArtifact, newLoop));
newLoop.setOperationalPolicies(createOperationalPolicies(csar, blueprintArtifact, newLoop));
- // Set SVG XML computed
- // newLoop.setSvgRepresentation(svgRepresentation);
- newLoop.setGlobalPropertiesJson(createGlobalPropertiesJson(csar, blueprintArtifact));
- newLoop.setModelPropertiesJson(createModelPropertiesJson(csar, blueprintArtifact));
+
+ newLoop.setSvgRepresentation(svgFacade.getSvgImage(microServicesChain));
+ newLoop.setGlobalPropertiesJson(createGlobalPropertiesJson(blueprintArtifact));
+ newLoop.setModelPropertiesJson(createModelPropertiesJson(csar));
DcaeInventoryResponse dcaeResponse = queryDcaeToGetServiceTypeId(blueprintArtifact);
newLoop.setDcaeBlueprintId(dcaeResponse.getTypeId());
return newLoop;
blueprintArtifact.getBlueprintArtifactName()), newLoop, new JsonObject())));
}
- private HashSet<MicroServicePolicy> createMicroServicePolicies(CsarHandler csar,
- BlueprintArtifact blueprintArtifact, Loop newLoop) throws IOException {
+ private HashSet<MicroServicePolicy> createMicroServicePolicies(List<MicroService> microServicesChain,
+ CsarHandler csar, BlueprintArtifact blueprintArtifact, Loop newLoop) throws IOException {
HashSet<MicroServicePolicy> newSet = new HashSet<>();
- for (MicroService microService : blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint())) {
- newSet.add(new MicroServicePolicy(microService.getName(), csar.getPolicyModelYaml().orElse(""), false,
- new HashSet<>(Arrays.asList(newLoop))));
+
+ for (MicroService microService : microServicesChain) {
+ MicroServicePolicy microServicePolicy = new MicroServicePolicy(
+ Policy.generatePolicyName(microService.getName(), csar.getSdcNotification().getServiceName(),
+ csar.getSdcNotification().getServiceVersion(),
+ blueprintArtifact.getResourceAttached().getResourceInstanceName(),
+ blueprintArtifact.getBlueprintArtifactName()), microService.getModelType(),
+ csar.getPolicyModelYaml().orElse(""), false, new HashSet<>(Arrays.asList(newLoop)), microService.getBlueprintName());
+
+ newSet.add(microServicePolicy);
+ microService.setMappedNameJpa(microServicePolicy.getName());
}
return newSet;
}
- private JsonObject createGlobalPropertiesJson(CsarHandler csar, BlueprintArtifact blueprintArtifact) {
+ private JsonObject createGlobalPropertiesJson(BlueprintArtifact blueprintArtifact) {
JsonObject globalProperties = new JsonObject();
globalProperties.add("dcaeDeployParameters", getAllBlueprintParametersInJson(blueprintArtifact));
return globalProperties;
-
}
- private JsonObject createModelPropertiesJson(CsarHandler csar, BlueprintArtifact blueprintArtifact) {
+ private JsonObject createModelPropertiesJson(CsarHandler csar) {
JsonObject modelProperties = new JsonObject();
Gson gson = new Gson();
modelProperties.add("serviceDetails",
/**
* ll get the latest version of the artifact (version can be specified to DCAE
- * call)
+ * call).
*
* @return The DcaeInventoryResponse object containing the dcae values
*/