package org.onap.clamp.loop;
-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.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
*/
private static final long serialVersionUID = -286522707701388642L;
- @Transient
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(Loop.class);
-
@Id
@Expose
@Column(nullable = false, name = "name", unique = true)
this.setModelService(loopTemplate.getModelService());
loopTemplate.getLoopElementModelsUsed().forEach(element -> {
if (LoopElementModel.MICRO_SERVICE_TYPE.equals(element.getLoopElementModel().getLoopElementType())) {
- try {
- this.addMicroServicePolicy((MicroServicePolicy) element.getLoopElementModel()
- .createPolicyInstance(this, toscaConverter));
- } catch (IOException e) {
- logger.error("Exception caught when creating the microservice policy instance of the loop "
- + "instance", e);
- }
+ this.addMicroServicePolicy((MicroServicePolicy) element.getLoopElementModel()
+ .createPolicyInstance(this, toscaConverter));
}
else if (LoopElementModel.OPERATIONAL_POLICY_TYPE
.equals(element.getLoopElementModel().getLoopElementType())) {
- try {
- this.addOperationalPolicy((OperationalPolicy) element.getLoopElementModel()
- .createPolicyInstance(this, toscaConverter));
- } catch (IOException e) {
- logger.error("Exception caught when creating the operational policy instance of the loop instance",
- e);
- }
+ this.addOperationalPolicy((OperationalPolicy) element.getLoopElementModel()
+ .createPolicyInstance(this, toscaConverter));
}
});
}
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.List;
+import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
+import org.onap.clamp.policy.microservice.MicroServicePolicyService;
import org.onap.clamp.policy.operational.OperationalPolicy;
+import org.onap.clamp.policy.operational.OperationalPolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
public class LoopController {
private final LoopService loopService;
- private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {}.getType();
- private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {}.getType();
+ private final ToscaConverterWithDictionarySupport toscaConverter;
+ private final OperationalPolicyService operationalPolicyService;
+
+ private final MicroServicePolicyService microServicePolicyService;
+
+ private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
+ }.getType();
+
+ private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
+ }.getType();
+
+
+ /**
+ * Constructor.
+ *
+ * @param loopService loopService
+ * @param operationalPolicyService operationalPolicyService
+ * @param microServicePolicyService microServicePolicyService
+ * @param toscaConverter toscaConverter
+ */
@Autowired
- public LoopController(LoopService loopService) {
+ public LoopController(LoopService loopService, OperationalPolicyService operationalPolicyService,
+ MicroServicePolicyService microServicePolicyService,
+ ToscaConverterWithDictionarySupport toscaConverter) {
this.loopService = loopService;
+ this.toscaConverter = toscaConverter;
+ this.operationalPolicyService = operationalPolicyService;
+ this.microServicePolicyService = microServicePolicyService;
}
public Loop createLoop(String loopName, String templateName) {
/**
* Refresh the Operational Policy Json representation of the loop.
*
- * @param loopName The loop name
- * @return The refreshed Loop
+ * @param loop The loop
+ * @param operationalPolicyName The operational policy name that needs a refresh
+ * @return The loop object
+ */
+ public Loop refreshOperationalPolicyJsonRepresentation(Loop loop, String operationalPolicyName) {
+ for (OperationalPolicy operationalPolicy : loop.getOperationalPolicies()) {
+ if (operationalPolicy.getName().equals(operationalPolicyName)) {
+ this.operationalPolicyService
+ .refreshOperationalPolicyJsonRepresentation(operationalPolicy, toscaConverter);
+ }
+ }
+ return loop;
+ }
+
+ /**
+ * Refresh the Config Policy Json representation of the loop.
+ *
+ * @param loop The loop
+ * @param microServicePolicyName The microservice policy name that needs a refresh
+ * @return The loop object
*/
- public Loop refreshOpPolicyJsonRepresentation(String loopName) {
- return loopService.refreshOpPolicyJsonRepresentation(loopName);
+ public Loop refreshMicroServicePolicyJsonRepresentation(Loop loop, String microServicePolicyName) {
+ for (MicroServicePolicy microServicePolicy : loop.getMicroServicePolicies()) {
+ if (microServicePolicy.getName().equals(microServicePolicyName)) {
+ this.microServicePolicyService
+ .refreshMicroServicePolicyJsonRepresentation(microServicePolicy, toscaConverter);
+ }
+ }
+ return loop;
}
}
return null;
}
loop.addOperationalPolicy(
- new OperationalPolicy(loop,loop.getModelService(), policyModel, toscaConverter));
+ new OperationalPolicy(loop, loop.getModelService(), policyModel, toscaConverter));
return loopsRepository.saveAndFlush(loop);
}
/**
* This method remove an operational policy to a loop instance.
*
- * @param loopName The loop name
- * @param policyType The policy model type
+ * @param loopName The loop name
+ * @param policyType The policy model type
* @param policyVersion The policy model version
* @return The loop modified
*/
return null;
}
for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) {
- if (opPolicy.getPolicyModel().getPolicyModelType().equals(policyType) &&
- opPolicy.getPolicyModel().getVersion().equals(policyVersion)) {
+ if (opPolicy.getPolicyModel().getPolicyModelType().equals(policyType)
+ && opPolicy.getPolicyModel().getVersion().equals(policyVersion)) {
loop.removeOperationalPolicy(opPolicy);
break;
}
return loopsRepository.findById(loopName)
.orElseThrow(() -> new EntityNotFoundException("Couldn't find closed loop named: " + loopName));
}
-
- /**
- * Api to refresh the Operational Policy UI window.
- *
- * @param loopName The loop Name
- * @return The refreshed loop object
- */
- public Loop refreshOpPolicyJsonRepresentation(String loopName) {
- Loop loop = findClosedLoopByName(loopName);
- Set<OperationalPolicy> policyList = loop.getOperationalPolicies();
- for (OperationalPolicy policy : policyList) {
- policy.updateJsonRepresentation();
- }
- loop.setOperationalPolicies(policyList);
- return loopsRepository.save(loop);
- }
}
+
package org.onap.clamp.loop.template;
import com.google.gson.annotations.Expose;
-import java.io.IOException;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
* Create a policy instance from the current loop element model.
*
* @return A Policy object.
- * @throws IOException in case of failure when creating an operational policy
*/
- public Policy createPolicyInstance(Loop loop, ToscaConverterWithDictionarySupport toscaConverter)
- throws IOException {
+ public Policy createPolicyInstance(Loop loop, ToscaConverterWithDictionarySupport toscaConverter) {
if (LoopElementModel.MICRO_SERVICE_TYPE.equals(this.getLoopElementType())) {
return new MicroServicePolicy(loop, loop.getModelService(), this, toscaConverter);
}
else if (LoopElementModel.OPERATIONAL_POLICY_TYPE.equals(this.getLoopElementType())) {
return new OperationalPolicy(loop, loop.getModelService(), this, toscaConverter);
- } else {
+ }
+ else {
return null;
}
}
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.json.JSONObject;
+import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
import org.onap.clamp.loop.common.AuditEntity;
import org.onap.clamp.loop.template.LoopElementModel;
this.jsonRepresentation = jsonRepresentation;
}
+ /**
+ * Regenerate the Policy Json Representation.
+ *
+ * @param toscaConverter The tosca converter required to regenerate the json schema
+ */
+ public abstract void updateJsonRepresentation(ToscaConverterWithDictionarySupport toscaConverter);
+
/**
* policyModel getter.
*
package org.onap.clamp.policy.microservice;
-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.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
-import javax.persistence.Transient;
import org.apache.commons.lang3.RandomStringUtils;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
*/
private static final long serialVersionUID = 6271238288583332616L;
- @Transient
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(MicroServicePolicy.class);
-
@Expose
@Id
@Column(nullable = false, name = "name", unique = true)
/**
* Constructor with tosca converter.
*
- * @param loop The loop instance
- * @param service The service model object
+ * @param loop The loop instance
+ * @param service The service model object
* @param loopElementModel The loop element model from which this microservice instance is created
- * @param toscaConverter The tosca converter that will used to convert the tosca policy model
+ * @param toscaConverter The tosca converter that will used to convert the tosca policy model
*/
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(), false,
- toscaConverter.convertToscaToJsonSchemaObject(
- loopElementModel.getPolicyModels().first().getPolicyModelTosca(),
- loopElementModel.getPolicyModels().first().getPolicyModelType()),
+ new JsonObject(),
loopElementModel, null, null);
+ this.updateJsonRepresentation(toscaConverter);
}
@Override
this.name = name;
}
+ @Override
+ public void updateJsonRepresentation(ToscaConverterWithDictionarySupport toscaConverter) {
+ toscaConverter.convertToscaToJsonSchemaObject(this.getPolicyModel().getPolicyModelTosca(),
+ this.getPolicyModel().getPolicyModelType());
+ }
+
public Boolean getShared() {
return shared;
}
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
+import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport;
import org.onap.clamp.loop.Loop;
import org.onap.clamp.policy.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
@Service
public class MicroServicePolicyService implements PolicyService<MicroServicePolicy> {
- private final MicroServicePolicyRepository repository;
+ private final MicroServicePolicyRepository microServiceRepository;
@Autowired
- public MicroServicePolicyService(MicroServicePolicyRepository repository) {
- this.repository = repository;
+ public MicroServicePolicyService(MicroServicePolicyRepository microServiceRepository) {
+ this.microServiceRepository = microServiceRepository;
}
@Override
@Override
public boolean isExisting(String policyName) {
- return repository.existsById(policyName);
+ return microServiceRepository.existsById(policyName);
}
/**
* @return The updated MicroService policy
*/
public MicroServicePolicy getAndUpdateMicroServicePolicy(Loop loop, MicroServicePolicy policy) {
- return repository.save(
- repository.findById(policy.getName()).map(p -> updateMicroservicePolicyProperties(p, policy, loop))
+ return microServiceRepository.save(
+ microServiceRepository
+ .findById(policy.getName()).map(p -> updateMicroservicePolicyProperties(p, policy, loop))
.orElse(new MicroServicePolicy(policy.getName(), policy.getPolicyModel(),
policy.getShared(), policy.getJsonRepresentation(), null, policy.getPdpGroup(),
policy.getPdpSubgroup())));
String deploymentUrl) {
microServicePolicy.setDcaeDeploymentId(deploymentId);
microServicePolicy.setDcaeDeploymentStatusUrl(deploymentUrl);
- repository.save(microServicePolicy);
+ microServiceRepository.save(microServicePolicy);
+ }
+
+
+ /**
+ * Api to refresh the MicroService Policy UI window.
+ *
+ * @param microServicePolicy The micro Service policy object
+ * @param toscaConverter the tosca converter required to convert the tosca model to json schema
+ */
+ public void refreshMicroServicePolicyJsonRepresentation(MicroServicePolicy microServicePolicy,
+ ToscaConverterWithDictionarySupport toscaConverter) {
+ microServicePolicy.updateJsonRepresentation(toscaConverter);
+ this.microServiceRepository.saveAndFlush(microServicePolicy);
+
}
}
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.Expose;
import java.io.IOException;
import java.io.Serializable;
* @param service The loop service
* @param loopElementModel The loop element model
* @param toscaConverter The tosca converter that must be used to create the Json representation
- * @throws IOException In case of issues with the legacy files (generated from resource files
*/
public OperationalPolicy(Loop loop, Service service, LoopElementModel loopElementModel,
- ToscaConverterWithDictionarySupport toscaConverter) throws IOException {
+ ToscaConverterWithDictionarySupport toscaConverter) {
this(Policy.generatePolicyName("OPERATIONAL", service.getName(), service.getVersion(),
RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), new JsonObject(),
new JsonObject(), loopElementModel.getPolicyModels().first(), loopElementModel, null, null);
this.setLoop(loop);
- this.setJsonRepresentation(generateJsonRepresentation(this, toscaConverter));
+ this.updateJsonRepresentation(toscaConverter);
}
/**
RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), new JsonObject(),
new JsonObject(), policyModel, null, null, null);
this.setLoop(loop);
- this.setJsonRepresentation(generateJsonRepresentation(this, toscaConverter));
- }
-
- /**
- * This method can generate a Json representation (json schema) for an operational policy.
- * This is mainly to support a legacy case and a generic case.
- * For the legacy case the operational policy given is modified (configurationJson).
- *
- * @param operationalPolicy The operational policy
- * @param toscaConverter The tosca converter
- * @return The Json Object with Json schema
- */
- public static JsonObject generateJsonRepresentation(OperationalPolicy operationalPolicy,
- ToscaConverterWithDictionarySupport toscaConverter)
- throws IOException {
- JsonObject jsonReturned = new JsonObject();
- if (operationalPolicy.getPolicyModel() == null) {
- return new JsonObject();
- }
- if (operationalPolicy.isLegacy()) {
- // Op policy Legacy case
- LegacyOperationalPolicy.preloadConfiguration(operationalPolicy.getConfigurationsJson(), operationalPolicy.loop);
- jsonReturned = OperationalPolicyRepresentationBuilder
- .generateOperationalPolicySchema(operationalPolicy.loop.getModelService());
- }
- else {
- // Generic Case
- jsonReturned = toscaConverter.convertToscaToJsonSchemaObject(
- operationalPolicy.getPolicyModel().getPolicyModelTosca(),
- operationalPolicy.getPolicyModel().getPolicyModelType());
- }
-
- return jsonReturned;
+ this.updateJsonRepresentation(toscaConverter);
}
public void setLoop(Loop loopName) {
this.name = name;
}
+ @Override
+ public void updateJsonRepresentation(ToscaConverterWithDictionarySupport toscaConverter) {
+ {
+ this.setJsonRepresentation(new JsonObject());
+ if (this.getPolicyModel() == null) {
+ return;
+ }
+ if (this.isLegacy()) {
+ // Op policy Legacy case
+ LegacyOperationalPolicy.preloadConfiguration(this.getConfigurationsJson(), this.loop);
+ this.setJsonRepresentation(OperationalPolicyRepresentationBuilder
+ .generateOperationalPolicySchema(this.loop.getModelService()));
+ }
+ else {
+ // Generic Case
+ this.setJsonRepresentation(toscaConverter.convertToscaToJsonSchemaObject(
+ this.getPolicyModel().getPolicyModelTosca(),
+ this.getPolicyModel().getPolicyModelType()));
+ }
+ }
+ }
+
@Override
public int hashCode() {
final int prime = 31;
logger.info("Guard policy payload: " + result);
return result;
}
-
- /**
- * Regenerate the Operational Policy Json Representation.
- */
- public void updateJsonRepresentation() {
- try {
- this.setJsonRepresentation(
- OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService()));
- } catch (JsonSyntaxException | IOException | NullPointerException e) {
- logger.error("Unable to generate the operational policy Schema ... ", e);
- this.setJsonRepresentation(new JsonObject());
- }
- }
}
package org.onap.clamp.policy.operational;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.util.Map.Entry;
import org.onap.clamp.clds.util.JsonUtils;
public class OperationalPolicyRepresentationBuilder {
+ private static final EELFLogger logger =
+ EELFManager.getInstance().getLogger(OperationalPolicyRepresentationBuilder.class);
+
/**
* This method generates the operational policy json representation that will be
* used by ui for rendering. It uses the model (VF and VFModule) defined in the
*
* @param modelJson The loop model json
* @return The json representation
- * @throws JsonSyntaxException If the schema template cannot be parsed
- * @throws IOException In case of issue when opening the schema template
*/
- public static JsonObject generateOperationalPolicySchema(Service modelJson)
- throws JsonSyntaxException, IOException {
- JsonObject jsonSchema = JsonUtils.GSON.fromJson(
- ResourceFileUtil.getResourceAsString("clds/json-schema/operational_policies/operational_policy.json"),
- JsonObject.class);
- jsonSchema.get("properties").getAsJsonObject()
- .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies")
- .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("target")
- .getAsJsonObject().get("anyOf").getAsJsonArray().addAll(createAnyOfArray(modelJson));
-
- // update CDS recipe and payload information to schema
- JsonArray actors = jsonSchema.get("properties").getAsJsonObject()
- .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies")
- .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("actor")
- .getAsJsonObject().get("anyOf").getAsJsonArray();
-
- for (JsonElement actor : actors) {
- if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get("title").getAsString())) {
- actor.getAsJsonObject().get("properties").getAsJsonObject().get("type").getAsJsonObject()
- .get("anyOf").getAsJsonArray()
- .addAll(createAnyOfArrayForCdsRecipe(modelJson.getResourceDetails()));
+ public static JsonObject generateOperationalPolicySchema(Service modelJson) {
+
+ JsonObject jsonSchema = null;
+ try {
+ jsonSchema = JsonUtils.GSON.fromJson(
+ ResourceFileUtil
+ .getResourceAsString("clds/json-schema/operational_policies/operational_policy.json"),
+ JsonObject.class);
+ jsonSchema.get("properties").getAsJsonObject()
+ .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies")
+ .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("target")
+ .getAsJsonObject().get("anyOf").getAsJsonArray().addAll(createAnyOfArray(modelJson));
+
+ // update CDS recipe and payload information to schema
+ JsonArray actors = jsonSchema.get("properties").getAsJsonObject()
+ .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies")
+ .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("actor")
+ .getAsJsonObject().get("anyOf").getAsJsonArray();
+
+ for (JsonElement actor : actors) {
+ if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get("title").getAsString())) {
+ actor.getAsJsonObject().get("properties").getAsJsonObject().get("type").getAsJsonObject()
+ .get("anyOf").getAsJsonArray()
+ .addAll(createAnyOfArrayForCdsRecipe(modelJson.getResourceDetails()));
+ }
}
+ return jsonSchema;
+ } catch (IOException e) {
+ logger.error("Unable to generate the json schema because of an exception",e);
+ return new JsonObject();
}
-
- return jsonSchema;
}
private static JsonObject createSchemaProperty(String title, String type, String defaultValue, String readOnlyFlag,
package org.onap.clamp.policy.operational;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
+import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport;
import org.onap.clamp.loop.Loop;
import org.onap.clamp.loop.template.PolicyModelsRepository;
import org.onap.clamp.policy.PolicyService;
private final PolicyModelsRepository policyModelsRepository;
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(OperationalPolicyService.class);
+
@Autowired
public OperationalPolicyService(OperationalPolicyRepository repository,
PolicyModelsRepository policyModelsRepository) {
operationalPolicyRepository
.findById(policy.getName())
.map(p -> setConfiguration(p, policy))
- .orElse(initializeMissingFields(loop,policy)))
+ .orElse(initializeMissingFields(loop, policy)))
.collect(Collectors.toSet());
}
policy.setPdpSubgroup(newPolicy.getPdpSubgroup());
return policy;
}
+
+ /**
+ * Api to refresh the Operational Policy UI window.
+ *
+ * @param operationalPolicy The operational policy object
+ * @param toscaConverter the tosca converter required to convert the tosca model to json schema
+ */
+ public void refreshOperationalPolicyJsonRepresentation(OperationalPolicy operationalPolicy,
+ ToscaConverterWithDictionarySupport toscaConverter) {
+ operationalPolicy.updateJsonRepresentation(toscaConverter);
+ this.operationalPolicyRepository.saveAndFlush(operationalPolicy);
+ }
}
</doTry>
</route>
</put>
- <put uri="/v2/loop/refreshOpPolicyJsonSchema/{loopName}"
+ <put uri="/v2/loop/refreshMicroServicePolicyJsonSchema/{loopName}/{microServicePolicyName}"
+ outType="org.onap.clamp.loop.Loop" produces="application/json">
+ <route>
+ <removeHeaders pattern="*" excludePattern="loopName|microServicePolicyName" />
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Refresh Micro Service Policy UI for loop: ${header.loopName} and ${header.microServicePolicyName}" />
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'REFRESH Micro Service Policy UI request')" />
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to uri="direct:load-loop" />
+ <to
+ uri="bean:org.onap.clamp.loop.LoopController?method=refreshMicroServicePolicyJsonRepresentation(${exchangeProperty[loopObject]},${header.microServicePolicyName}})" />
+ <log loggingLevel="INFO"
+ message="REFRESH Micro Service policy request successfully executed for loop: ${header.loopName}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('REFRESH Micro Service policy request successfully executed','INFO',${exchangeProperty[loopObject]})" />
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" />
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>false</constant>
+ </handled>
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" />
+ <log loggingLevel="ERROR"
+ message="REFRESH Micro Service policy request failed for loop: ${header.loopName}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('REFRESH Micro Service policy request failed, Error reported: ${exception} - Body: ${exception.responseBody}','ERROR',${exchangeProperty[loopObject]})" />
+ </doCatch>
+ </doTry>
+ </route>
+ </put>
+ <put uri="/v2/loop/refreshOperationalPolicyJsonSchema/{loopName}/{operationalPolicyName}"
outType="org.onap.clamp.loop.Loop" produces="application/json">
<route>
- <removeHeaders pattern="*" excludePattern="loopName" />
+ <removeHeaders pattern="*" excludePattern="loopName|operationalPolicyName" />
<doTry>
<log loggingLevel="INFO"
- message="Refresh Operational Policy UI for loop: ${header.loopName}" />
+ message="Refresh Operational Policy UI for loop: ${header.loopName} and ${header.operationalPolicyName}" />
<to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'REFRESH OP Policy UI request')" />
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'REFRESH Operational Policy UI request')" />
<to
uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
<to uri="direct:load-loop" />
<to
- uri="bean:org.onap.clamp.loop.LoopController?method=refreshOpPolicyJsonRepresentation(${header.loopName})" />
+ uri="bean:org.onap.clamp.loop.LoopController?method=refreshOperationalPolicyJsonRepresentation(${exchangeProperty[loopObject]},${header.operationalPolicyName}})" />
<log loggingLevel="INFO"
- message="REFRESH request successfully executed for loop: ${header.loopName}" />
+ message="REFRESH operational policy request successfully executed for loop: ${header.loopName}" />
<to
- uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('REFRESH request successfully executed','INFO',${exchangeProperty[loopObject]})" />
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('REFRESH operational policy request successfully executed','INFO',${exchangeProperty[loopObject]})" />
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" />
<doCatch>
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" />
<log loggingLevel="ERROR"
- message="REFRESH request failed for loop: ${header.loopName}" />
+ message="REFRESH operational policy request failed for loop: ${header.loopName}" />
<to
- uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('REFRESH request failed, Error reported: ${exception} - Body: ${exception.responseBody}','ERROR',${exchangeProperty[loopObject]})" />
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('REFRESH operational policy request failed, Error reported: ${exception} - Body: ${exception.responseBody}','ERROR',${exchangeProperty[loopObject]})" />
</doCatch>
</doTry>
</route>
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
-
import java.io.IOException;
-
import org.junit.Test;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.loop.service.Service;
return this.loopJsonCache["name"];
}
- getOperationalPolicyConfigurationJson() {
- return this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"];
- }
-
getOperationalPolicyJsonSchema() {
return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"];
}
expect(loopCache.getLoopName()).toBe("LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca");
});
- it('getOperationalPolicyConfigurationJson', () => {
- const opPolicyConfig = {
- "guard_policies": {},
- "operational_policy": {
- "controlLoop": {},
- "policies": []
- }
- };
- expect(loopCache.getOperationalPolicyConfigurationJson()).toStrictEqual(opPolicyConfig);
- });
-
it('getOperationalPolicies', () => {
const opPolicy = [{
"name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
});
}
- static refreshOpPolicyJson(loopName) {
- return fetch('/restservices/clds/v2/loop/refreshOpPolicyJsonSchema/' + loopName, {
+ static refreshOperationalPolicyJson(loopName,operationalPolicyName) {
+ return fetch('/restservices/clds/v2/loop/refreshOperationalPolicyJsonSchema/' + loopName + '/' + operationalPolicyName, {
method: 'PUT',
headers: {
"Content-Type": "application/json"
});
}
+ static refreshMicroServicePolicyJson(loopName,microServicePolicyName) {
+ return fetch('/restservices/clds/v2/loop/refreshMicroServicePolicyJsonSchema/' + loopName + '/' + microServicePolicyName, {
+ method: 'PUT',
+ headers: {
+ "Content-Type": "application/json"
+ },
+ credentials: 'same-origin'
+ })
+ .then(function (response) {
+ console.debug("Refresh Operational Policy Json Schema response received: ", response.status);
+ if (response.ok) {
+ return response.json();
+ } else {
+ console.error("Refresh Operational Policy Json Schema query failed");
+ return {};
+ }
+ })
+ .catch(function (error) {
+ console.error("Refresh Operational Policy Json Schema error received", error);
+ return {};
+ });
+ }
+
static addOperationalPolicyType(loopName, policyType, policyVersion) {
return fetch('/restservices/clds/v2/loop/addOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion , {
method: 'PUT',
}
handleRefresh() {
- LoopService.refreshOpPolicyJson(this.state.loopCache.getLoopName()).then(data => {
+ LoopService.refreshOperationalPolicyJson(this.state.loopCache.getLoopName(), this.state.loopCache.getOperationalPolicies()[0]).then(data => {
var newLoopCache = new LoopCache(data);
var schema_json = newLoopCache.getOperationalPolicyJsonSchema();
var operationalPoliciesData = newLoopCache.getOperationalPoliciesNoJsonSchema();