summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authorxuegao <xg353y@intl.att.com>2019-11-08 13:10:36 +0100
committerxuegao <xg353y@intl.att.com>2019-11-18 10:41:47 +0100
commit289e8e1f1858e970f92b50a1e601521edeefd44f (patch)
tree78246ad3b62c744626811949aea653d0ee7c8e58 /src/main/java/org/onap
parent77b0be1b734ae1f785fb35a59387ac5fbcf19266 (diff)
Create Service object
User Service object to store loop service and resource realted info. Issue-ID: CLAMP-545 Change-Id: I0df6f5d43d7e0575346e02a27bca5c0b5ecdb0a0 Signed-off-by: xuegao <xg353y@intl.att.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java18
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopCsarInstaller.java18
-rw-r--r--src/main/java/org/onap/clamp/loop/service/Service.java137
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java14
4 files changed, 164 insertions, 23 deletions
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index 37d597eeb..ef70ba80e 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -48,6 +48,7 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -61,6 +62,7 @@ import org.onap.clamp.loop.components.external.DcaeComponent;
import org.onap.clamp.loop.components.external.ExternalComponent;
import org.onap.clamp.loop.components.external.PolicyComponent;
import org.onap.clamp.loop.log.LoopLog;
+import org.onap.clamp.loop.service.Service;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
import org.onap.clamp.policy.operational.OperationalPolicyRepresentationBuilder;
@@ -109,9 +111,9 @@ public class Loop implements Serializable {
private JsonObject globalPropertiesJson;
@Expose
- @Type(type = "json")
- @Column(columnDefinition = "json", name = "model_properties_json")
- private JsonObject modelPropertiesJson;
+ @ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
+ @JoinColumn(name = "service_uuid")
+ private Service modelService;
@Column(columnDefinition = "MEDIUMTEXT", nullable = false, name = "blueprint_yaml")
private String blueprint;
@@ -266,15 +268,15 @@ public class Loop implements Serializable {
this.dcaeBlueprintId = dcaeBlueprintId;
}
- public JsonObject getModelPropertiesJson() {
- return modelPropertiesJson;
+ public Service getModelService() {
+ return modelService;
}
- void setModelPropertiesJson(JsonObject modelPropertiesJson) {
- this.modelPropertiesJson = modelPropertiesJson;
+ void setModelService(Service modelService) {
+ this.modelService = modelService;
try {
this.operationalPolicySchema = OperationalPolicyRepresentationBuilder
- .generateOperationalPolicySchema(this.getModelPropertiesJson());
+ .generateOperationalPolicySchema(this.getModelService());
} catch (JsonSyntaxException | IOException | NullPointerException e) {
logger.error("Unable to generate the operational policy Schema ... ", e);
this.operationalPolicySchema = new JsonObject();
diff --git a/src/main/java/org/onap/clamp/loop/LoopCsarInstaller.java b/src/main/java/org/onap/clamp/loop/LoopCsarInstaller.java
index b8bc1f524..55009bc22 100644
--- a/src/main/java/org/onap/clamp/loop/LoopCsarInstaller.java
+++ b/src/main/java/org/onap/clamp/loop/LoopCsarInstaller.java
@@ -46,6 +46,7 @@ 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.loop.service.Service;
import org.onap.clamp.policy.Policy;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -138,7 +139,7 @@ public class LoopCsarInstaller implements CsarInstaller {
if (microServicesChain.isEmpty()) {
microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint());
}
- newLoop.setModelPropertiesJson(createModelPropertiesJson(csar));
+ newLoop.setModelService(createServiceModel(csar));
newLoop.setMicroServicePolicies(
createMicroServicePolicies(microServicesChain, csar, blueprintArtifact, newLoop));
newLoop.setOperationalPolicies(createOperationalPolicies(csar, blueprintArtifact, newLoop));
@@ -219,16 +220,17 @@ public class LoopCsarInstaller implements CsarInstaller {
return resourcesProp;
}
- private static JsonObject createModelPropertiesJson(CsarHandler csar) {
- JsonObject modelProperties = new JsonObject();
- // Add service details
- modelProperties.add("serviceDetails", JsonUtils.GSON.fromJson(
- JsonUtils.GSON.toJson(csar.getSdcCsarHelper().getServiceMetadataAllProperties()), JsonObject.class));
+ private Service createServiceModel(CsarHandler csar) {
+ JsonObject serviceDetails = JsonUtils.GSON.fromJson(
+ JsonUtils.GSON.toJson(csar.getSdcCsarHelper().getServiceMetadataAllProperties()), JsonObject.class);
+
// Add properties details for each type, VfModule, VF, VFC, ....
JsonObject resourcesProp = createServicePropertiesByType(csar);
resourcesProp.add("VFModule", createVfModuleProperties(csar));
- modelProperties.add("resourceDetails", resourcesProp);
- return modelProperties;
+
+ Service modelService = new Service(serviceDetails, resourcesProp);
+
+ return modelService;
}
private JsonObject getAllBlueprintParametersInJson(BlueprintArtifact blueprintArtifact, Loop newLoop) {
diff --git a/src/main/java/org/onap/clamp/loop/service/Service.java b/src/main/java/org/onap/clamp/loop/service/Service.java
new file mode 100644
index 000000000..ac1216b9d
--- /dev/null
+++ b/src/main/java/org/onap/clamp/loop/service/Service.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop.service;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.gson.JsonObject;
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.TypeDefs;
+import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
+
+
+@Entity
+@Table(name = "services")
+@TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
+public class Service implements Serializable {
+
+ /**
+ * The serial version id.
+ */
+ private static final long serialVersionUID = 1331119060272760758L;
+
+ @Transient
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(Service.class);
+
+ @Id
+ @Column(name = "service_uuid", unique = true)
+ private String serviceUuid;
+
+ @Column(nullable = false, name = "name")
+ private String name;
+
+ @Expose
+ @Type(type = "json")
+ @Column(columnDefinition = "json", name = "service_details")
+ private JsonObject serviceDetails;
+
+ @Expose
+ @Type(type = "json")
+ @Column(columnDefinition = "json", name = "resource_details")
+ private JsonObject resourceDetails;
+
+ /**
+ * Public constructor.
+ */
+ public Service() {
+ }
+
+ /**
+ * Constructor.
+ */
+ public Service(JsonObject serviceDetails, JsonObject resourceDetails) {
+ this.name = serviceDetails.get("name").getAsString();
+ this.serviceUuid = serviceDetails.get("UUID").getAsString();
+ this.serviceDetails = serviceDetails;
+ this.resourceDetails = resourceDetails;
+ }
+
+ public String getServiceUuid() {
+ return serviceUuid;
+ }
+
+ public JsonObject getServiceDetails() {
+ return serviceDetails;
+ }
+
+ public JsonObject getResourceDetails() {
+ return resourceDetails;
+ }
+
+ public JsonObject getResourceByType(String type) {
+ return (JsonObject) resourceDetails.get(type);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((serviceUuid == null) ? 0 : serviceUuid.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Service other = (Service) obj;
+ if (serviceUuid == null) {
+ if (other.serviceUuid != null) {
+ return false;
+ }
+ } else if (!serviceUuid.equals(other.serviceUuid)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
index f6f3f498d..1d0d99080 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
@@ -33,6 +33,7 @@ import java.util.Map.Entry;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.clamp.loop.service.Service;
public class OperationalPolicyRepresentationBuilder {
@@ -47,7 +48,7 @@ public class OperationalPolicyRepresentationBuilder {
* @throws JsonSyntaxException If the schema template cannot be parsed
* @throws IOException In case of issue when opening the schema template
*/
- public static JsonObject generateOperationalPolicySchema(JsonObject modelJson)
+ public static JsonObject generateOperationalPolicySchema(Service modelJson)
throws JsonSyntaxException, IOException {
JsonObject jsonSchema = JsonUtils.GSON.fromJson(
ResourceFileUtil.getResourceAsString("clds/json-schema/operational_policies/operational_policy.json"),
@@ -78,9 +79,9 @@ public class OperationalPolicyRepresentationBuilder {
return property;
}
- private static JsonArray createVnfSchema(JsonObject modelJson) {
+ private static JsonArray createVnfSchema(Service modelService) {
JsonArray vnfSchemaArray = new JsonArray();
- JsonObject modelVnfs = modelJson.get("resourceDetails").getAsJsonObject().get("VF").getAsJsonObject();
+ JsonObject modelVnfs = modelService.getResourceByType("VF");
for (Entry<String, JsonElement> entry : modelVnfs.entrySet()) {
JsonObject vnfOneOfSchema = new JsonObject();
@@ -96,10 +97,9 @@ public class OperationalPolicyRepresentationBuilder {
return vnfSchemaArray;
}
- private static JsonArray createVfModuleSchema(JsonObject modelJson) {
+ private static JsonArray createVfModuleSchema(Service modelService) {
JsonArray vfModuleOneOfSchemaArray = new JsonArray();
- JsonObject modelVfModules = modelJson.get("resourceDetails").getAsJsonObject().get("VFModule")
- .getAsJsonObject();
+ JsonObject modelVfModules = modelService.getResourceByType("VFModule");
for (Entry<String, JsonElement> entry : modelVfModules.entrySet()) {
JsonObject vfModuleOneOfSchema = new JsonObject();
@@ -137,7 +137,7 @@ public class OperationalPolicyRepresentationBuilder {
return vfModuleOneOfSchemaArray;
}
- private static JsonArray createAnyOfArray(JsonObject modelJson) {
+ private static JsonArray createAnyOfArray(Service modelJson) {
JsonArray targetOneOfStructure = new JsonArray();
targetOneOfStructure.addAll(createVnfSchema(modelJson));
targetOneOfStructure.addAll(createVfModuleSchema(modelJson));