Give a better name to the policies so that it's easier to know which modle has been used
Issue-ID: CLAMP-792
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: I7c6f25eb5075d6e4d114cecd705530a656875cd9
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.ExchangeBuilder;
logger.info("Downloading the policy model " + policyType + "/" + policyVersion);
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
- options.setIndent(2);
+ options.setIndent(4);
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
- return (new Yaml(options)).dump(callCamelRoute(
+ Yaml yamlParser = new Yaml(options);
+ return yamlParser.dump((Map<String, Object>) yamlParser.load(callCamelRoute(
ExchangeBuilder.anExchange(camelContext).withProperty("policyModelName", policyType)
.withProperty("policyModelVersion", policyVersion).build(), "direct:get-policy-model",
- "Get one policy"));
+ "Get one policy")));
}
/**
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
-
import javax.persistence.Transient;
-
import org.apache.camel.Exchange;
import org.onap.clamp.loop.Loop;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
* @return The json, payload to send
*/
public static String createPoliciesPayloadPdpGroup(Loop loop) {
- HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap = new HashMap <String,HashMap<String, List<JsonObject>>>();
+ HashMap<String, HashMap<String, List<JsonObject>>> pdpGroupMap = new HashMap<>();
for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) {
pdpGroupMap = updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(),
- opPolicy.getName(),
- opPolicy.getPolicyModel().getVersion(), pdpGroupMap);
+ opPolicy.getName(),
+ opPolicy.getPolicyModel().getVersion(), pdpGroupMap);
}
for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) {
}
String payload = new GsonBuilder().setPrettyPrinting().create()
- .toJson(generateActivatePdpGroupPayload(pdpGroupMap));
+ .toJson(generateActivatePdpGroupPayload(pdpGroupMap));
logger.info("PdpGroup policy payload: " + payload);
return payload;
}
- private static HashMap<String,HashMap<String, List<JsonObject>>> updatePdpGroupMap (String pdpGroup, String pdpSubGroup, String policyName,
- String policyModelVersion, HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap){
+ private static HashMap<String, HashMap<String, List<JsonObject>>> updatePdpGroupMap(String pdpGroup,
+ String pdpSubGroup,
+ String policyName,
+ String policyModelVersion,
+ HashMap<String, HashMap<String,
+ List<JsonObject>>> pdpGroupMap) {
JsonObject policyJson = new JsonObject();
policyJson.addProperty("name", policyName);
HashMap<String, List<JsonObject>> pdpSubGroupMap;
List<JsonObject> policyList;
if (pdpGroupMap.get(pdpGroup) == null) {
- pdpSubGroupMap = new HashMap <String, List<JsonObject>>();
+ pdpSubGroupMap = new HashMap<String, List<JsonObject>>();
policyList = new LinkedList<JsonObject>();
- } else {
+ }
+ else {
pdpSubGroupMap = pdpGroupMap.get(pdpGroup);
if (pdpSubGroupMap.get(pdpSubGroup) == null) {
policyList = new LinkedList<JsonObject>();
- } else {
- policyList = (List<JsonObject>)pdpSubGroupMap.get(pdpSubGroup);
+ }
+ else {
+ policyList = (List<JsonObject>) pdpSubGroupMap.get(pdpSubGroup);
}
}
policyList.add(policyJson);
return pdpGroupMap;
}
- private static JsonObject generateActivatePdpGroupPayload(HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap) {
+ private static JsonObject generateActivatePdpGroupPayload(
+ HashMap<String, HashMap<String, List<JsonObject>>> pdpGroupMap) {
JsonArray payloadArray = new JsonArray();
for (Entry<String, HashMap<String, List<JsonObject>>> pdpGroupInfo : pdpGroupMap.entrySet()) {
JsonObject pdpGroupNode = new JsonObject();
ExternalComponentState newState = NOT_SENT;
if (found && deployed) {
newState = SENT_AND_DEPLOYED;
- } else if (found) {
+ }
+ else if (found) {
newState = SENT;
- } else if (deployed) {
+ }
+ else if (deployed) {
newState = IN_ERROR;
}
return newState;
}
private static ExternalComponentState mergeStates(ExternalComponentState oldState,
- ExternalComponentState newState) {
+ ExternalComponentState newState) {
return (oldState.compareTo(newState) < 0) ? newState : oldState;
}
* this method is called multiple times from the camel route and must be reset
* for a new global policy state retrieval. The state to compute the global
* policy state is stored in this class.
- *
*/
@Override
public ExternalComponentState computeState(Exchange camelExchange) {
public MicroServicePolicy(Loop loop, Service service, LoopElementModel loopElementModel,
ToscaConverterWithDictionarySupport toscaConverter) {
this(Policy.generatePolicyName("MICROSERVICE", service.getName(), service.getVersion(),
- RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)),
+ loopElementModel.getPolicyModels().first().getPolicyAcronym() + '_'
+ + loopElementModel.getPolicyModels().first().getVersion(),
+ RandomStringUtils.randomAlphanumeric(3)),
loopElementModel.getPolicyModels().first(), false, new JsonObject(), loopElementModel, null, null);
this.updateJsonRepresentation(toscaConverter, service);
}
public OperationalPolicy(Loop loop, Service service, LoopElementModel loopElementModel,
ToscaConverterWithDictionarySupport toscaConverter) {
this(Policy.generatePolicyName("OPERATIONAL", service.getName(), service.getVersion(),
- RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), new JsonObject(),
+ loopElementModel.getPolicyModels().first().getPolicyAcronym() + '_'
+ + loopElementModel.getPolicyModels().first().getVersion(),
+ RandomStringUtils.randomAlphanumeric(3)), new JsonObject(),
new JsonObject(), loopElementModel.getPolicyModels().first(), loopElementModel, null, null);
this.setLoop(loop);
this.updateJsonRepresentation(toscaConverter, service);
public OperationalPolicy(Loop loop, Service service, PolicyModel policyModel,
ToscaConverterWithDictionarySupport toscaConverter) throws IOException {
this(Policy.generatePolicyName("OPERATIONAL", service.getName(), service.getVersion(),
- RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), new JsonObject(),
+ policyModel.getPolicyAcronym() + '_' + policyModel.getVersion(),
+ RandomStringUtils.randomAlphanumeric(3)),
+ new JsonObject(),
new JsonObject(), policyModel, null, null, null);
this.setLoop(loop);
this.updateJsonRepresentation(toscaConverter, service);
package org.onap.clamp.loop.deploy;
import com.google.gson.JsonObject;
-
import java.io.IOException;
import java.util.LinkedHashSet;
-
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
public class BlueprintInputParametersTest {
+ /**
+ * getDeploymentParametersinJsonMultiBlueprintsTest.
+ *
+ * @throws IOException in case of failure
+ * @throws SdcToscaParserException in case of failure
+ */
@Test
public void getDeploymentParametersinJsonMultiBlueprintsTest() throws IOException, SdcToscaParserException {
- Loop loop = Mockito.mock(Loop.class);
+
MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class);
Mockito.when(umService1.getName()).thenReturn("testName1");
Mockito.when(loopElement3.getBlueprint()).thenReturn(blueprint3);
Mockito.when(umService3.getLoopElementModel()).thenReturn(loopElement3);
- LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<MicroServicePolicy>();
+ LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<>();
umServiceSet.add(umService1);
umServiceSet.add(umService2);
umServiceSet.add(umService3);
+ Loop loop = Mockito.mock(Loop.class);
Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet);
LoopTemplate template = Mockito.mock(LoopTemplate.class);
JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
- ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters-multi-blueprints.json"));
+ ResourceFileUtil.getResourceAsString(
+ "example/sdc/expected-result/deployment-parameters-multi-blueprints.json"));
}
+ /**
+ * getDeploymentParametersInJsonSingleBlueprintTest.
+ *
+ * @throws IOException In case of failure
+ * @throws SdcToscaParserException In case of failure
+ */
@Test
public void getDeploymentParametersInJsonSingleBlueprintTest() throws IOException, SdcToscaParserException {
Loop loop = Mockito.mock(Loop.class);
JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
- ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters-single-blueprint.json"));
+ ResourceFileUtil.getResourceAsString(
+ "example/sdc/expected-result/deployment-parameters-single-blueprint.json"));
}
}