aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-04-09 14:29:28 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-09 14:29:28 +0000
commite678e5af567040022f23ed7a1ba1723b82434418 (patch)
tree872285e1dbef2ec2b65a62819f3fe006f532811d
parent9ede89131044d171187c5be906aefee615a0e568 (diff)
parent7e63a8833ae226738d858a3ff1aaf715f9b51d6b (diff)
Merge "Parse new model ids from operational policy"
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java64
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java24
-rw-r--r--models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java71
-rw-r--r--models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/TargetType.java18
4 files changed, 122 insertions, 55 deletions
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
index 2a14bb19a..6d8fa4bd2 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
@@ -164,10 +164,11 @@ public class SoActorServiceProvider implements Actor {
// Find the index for base vf module and non-base vf module
AaiNqInventoryResponseItem baseItem = findVfModule(aaiResponseWrapper, true);
- AaiNqInventoryResponseItem vfModuleItem = findVfModule(aaiResponseWrapper, false);
+
+ SoModelInfo soModelInfo = prepareSoModelInfo(policy);
// Report the error if either base vf module or non-base vf module is not found
- if (baseItem == null || vfModuleItem == null) {
+ if (baseItem == null || soModelInfo == null) {
logger.error("Either base or non-base vf module is not found from AAI response.");
return null;
}
@@ -175,9 +176,31 @@ public class SoActorServiceProvider implements Actor {
// Construct SO Request for a policy's recipe
if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) {
return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem,
- vfModuleItem);
+ soModelInfo);
} else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
- return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, vfModuleItem);
+ return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, soModelInfo, policy);
+ } else {
+ return null;
+ }
+ }
+
+ private SoModelInfo prepareSoModelInfo(Policy policy) {
+
+ SoModelInfo soModelInfo = new SoModelInfo();
+ if ((policy.getTarget() != null
+ && (policy.getTarget().getModelCustomizationId() != null))
+ && (policy.getTarget().getModelInvariantId() != null)
+ && (policy.getTarget().getModelName() != null)
+ && (policy.getTarget().getModelVersion() != null)
+ && (policy.getTarget().getModelVersionId() != null)) {
+
+ soModelInfo.setModelCustomizationId(policy.getTarget().getModelCustomizationId());
+ soModelInfo.setModelInvariantId(policy.getTarget().getModelInvariantId());
+ soModelInfo.setModelName(policy.getTarget().getModelName());
+ soModelInfo.setModelVersion(policy.getTarget().getModelVersion());
+ soModelInfo.setModelVersionId(policy.getTarget().getModelVersionId());
+
+ return soModelInfo;
} else {
return null;
}
@@ -197,7 +220,7 @@ public class SoActorServiceProvider implements Actor {
private SoRequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy,
AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem,
AaiNqInventoryResponseItem vnfServiceItem,
- AaiNqInventoryResponseItem vfModuleItem) {
+ SoModelInfo vfModuleItem) {
SoRequest request = new SoRequest();
request.setOperationType(SoOperationType.SCALE_OUT);
//
@@ -211,8 +234,7 @@ public class SoActorServiceProvider implements Actor {
// cloudConfiguration
request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem));
// modelInfo
- request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem));
- request.getRequestDetails().getModelInfo().setModelVersionId(vfModuleItem.getVfModule().getModelVersionId());
+ request.getRequestDetails().setModelInfo(vfModuleItem);
// requestInfo
request.getRequestDetails().setRequestInfo(constructRequestInfo());
@@ -296,7 +318,7 @@ public class SoActorServiceProvider implements Actor {
* @return SO delete vf-module request
*/
private SoRequest constructDeleteRequest(AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem
- vnfItem, AaiNqInventoryResponseItem vnfServiceItem, AaiNqInventoryResponseItem vfModuleItem) {
+ vnfItem, AaiNqInventoryResponseItem vnfServiceItem, SoModelInfo vfModuleItem, Policy policy) {
SoRequest request = new SoRequest();
request.setOperationType(SoOperationType.DELETE_VF_MODULE);
request.setRequestDetails(new SoRequestDetails());
@@ -306,12 +328,12 @@ public class SoActorServiceProvider implements Actor {
// cloudConfiguration
request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem));
// modelInfo
- request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem));
+ request.getRequestDetails().setModelInfo(prepareSoModelInfo(policy));
// requestInfo
request.getRequestDetails().setRequestInfo(constructRequestInfo());
// Save the instance IDs for the VNF, service and vfModule to static fields
preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance()
- .getServiceInstanceId(), vfModuleItem.getVfModule().getVfModuleId());
+ .getServiceInstanceId(), null);
if (logger.isDebugEnabled()) {
logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
@@ -333,28 +355,6 @@ public class SoActorServiceProvider implements Actor {
}
/**
- * Construct modelInfo of the vfModule for the SO requestDetails.
- *
- * @param vfModuleItem vf module item from A&AI named-query response
- * @return SO Model info for the vfModule
- */
- private SoModelInfo constructVfModuleModelInfo(AaiNqInventoryResponseItem vfModuleItem) {
- SoModelInfo soModelInfo = new SoModelInfo();
- soModelInfo.setModelType("vfModule");
- soModelInfo.setModelInvariantId(vfModuleItem.getVfModule().getModelInvariantId());
- soModelInfo.setModelCustomizationId(vfModuleItem.getVfModule().getModelCustomizationId());
-
- for (AaiNqExtraProperty prop : vfModuleItem.getExtraProperties().getExtraProperty()) {
- if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
- soModelInfo.setModelName(prop.getPropertyValue());
- } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
- soModelInfo.setModelVersion(prop.getPropertyValue());
- }
- }
- return soModelInfo;
- }
-
- /**
* Construct cloudConfiguration for the SO requestDetails.
*
* @param tenantItem tenant item from A&AI named-query response
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
index a7bdf1a76..8b4bcf20a 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
@@ -42,6 +42,7 @@ import org.onap.policy.aai.AaiNqResponseWrapper;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.so.SoOperationType;
import org.onap.policy.so.SoRequest;
import org.onap.policy.so.SoRequestParameters;
@@ -64,7 +65,9 @@ public class SoActorServiceProviderTest {
Policy policy = new Policy();
policy.setActor("Dorothy");
policy.setRecipe("GoToOz");
-
+
+ instantiateTarget(policy);
+
assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
policy.setActor("SO");
@@ -88,7 +91,7 @@ public class SoActorServiceProviderTest {
assertEquals("avalue", request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey"));
assertEquals(1, request.getRequestDetails().getConfigurationParameters().size());
assertEquals("cvalue", request.getRequestDetails().getConfigurationParameters().get(0).get("ckey"));
-
+
// payload with config, but no request params
policy.setPayload(makePayload());
policy.getPayload().remove(SoActorServiceProvider.REQ_PARAM_NM);
@@ -96,7 +99,7 @@ public class SoActorServiceProviderTest {
assertNotNull(request);
assertNull(request.getRequestDetails().getRequestParameters());
assertNotNull(request.getRequestDetails().getConfigurationParameters());
-
+
// payload with request, but no config params
policy.setPayload(makePayload());
policy.getPayload().remove(SoActorServiceProvider.CONFIG_PARAM_NM);
@@ -112,10 +115,13 @@ public class SoActorServiceProviderTest {
assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy,
loadAaiResponse(onset, "aai/AaiNqResponse-NoBase.json")));
+ policy.setTarget(null);
+
// response has no non-base VF modules (other than the "dummy")
assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy,
loadAaiResponse(onset, "aai/AaiNqResponse-NoNonBase.json")));
+ instantiateTarget(policy);
policy.setRecipe(VF_MODULE_DELETE);
SoRequest deleteRequest = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
assertNotNull(deleteRequest);
@@ -142,6 +148,18 @@ public class SoActorServiceProviderTest {
assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
}
+ private void instantiateTarget(Policy policy) {
+
+ Target target = new Target();
+ target.setModelCustomizationId("3e2d67ad-3495-4732-82f6-b0b872791fff");
+ target.setModelInvariantId("90b793b5-b8ae-4c36-b10b-4b6372859d3a");
+ target.setModelName("SproutScalingVf..scaling_sprout..module-1");
+ target.setModelVersion("1");
+ target.setModelVersionId("2210154d-e61a-4d7f-8fb9-0face1aee3f8");
+
+ policy.setTarget(target);
+ }
+
@Test
public void testSendRequest() {
try {
diff --git a/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java b/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java
index 6e7a8218a..b8432ba60 100644
--- a/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java
+++ b/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java
@@ -1,16 +1,17 @@
/*-
+/*-
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Tech Mahindra
* ================================================================================
* 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.
@@ -26,32 +27,78 @@ import java.io.Serializable;
public class Target implements Serializable {
private static final long serialVersionUID = 2180988443264988319L;
-
+
private String resourceId;
private TargetType type;
+ private String modelInvariantId;
+ private String modelVersionId;
+ private String modelName;
+ private String modelVersion;
+ private String modelCustomizationId;
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public void setModelVersionId(String modelVersionId) {
+ this.modelVersionId = modelVersionId;
+ }
+
+ public String getModelName() {
+ return modelName;
+ }
+
+ public void setModelName(String modelName) {
+ this.modelName = modelName;
+ }
+
+ public String getModelVersion() {
+ return modelVersion;
+ }
+
+ public void setModelVersion(String modelVersion) {
+ this.modelVersion = modelVersion;
+ }
+
+ public String getModelCustomizationId() {
+ return modelCustomizationId;
+ }
+
+ public void setModelCustomizationId(String modelCustomizationId) {
+ this.modelCustomizationId = modelCustomizationId;
+ } //techm
+
public Target() {
//Does Nothing Empty Constructor
}
-
+
public Target(TargetType type) {
this.type = type;
}
-
+
public Target(String resourceId) {
this.resourceId = resourceId;
}
-
+
public Target(TargetType type, String resourceId) {
this.type = type;
this.resourceId = resourceId;
}
-
+
public Target(Target target) {
this.type = target.type;
this.resourceId = target.resourceId;
}
-
+
public String getResourceID() {
return resourceId;
}
@@ -72,7 +119,7 @@ public class Target implements Serializable {
public String toString() {
return "Target [type=" + type + ", resourceId=" + resourceId + "]";
}
-
+
@Override
public int hashCode() {
final int prime = 31;
@@ -81,7 +128,7 @@ public class Target implements Serializable {
result = prime * result + ((resourceId == null) ? 0 : resourceId.hashCode());
return result;
}
-
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/TargetType.java b/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/TargetType.java
index 7e47f80d8..2b05d2858 100644
--- a/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/TargetType.java
+++ b/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/TargetType.java
@@ -2,15 +2,16 @@
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 Tech Mahindra
* ================================================================================
* 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.
@@ -24,16 +25,17 @@ package org.onap.policy.controlloop.policy;
public enum TargetType {
VM("VM"),
PNF("PNF"),
- VFC("VFC"),
- VNF("VNF")
+ VFC("VFC"),
+ VNF("VNF"),
+ VFMODULE("VFModule")
;
-
+
private String target;
-
+
private TargetType(String targetType) {
this.target = targetType;
}
-
+
@Override
public String toString() {
return this.target;