package org.onap.clamp.loop;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
import javax.persistence.Table;
+import javax.persistence.Transient;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
*/
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)
@Expose
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
+ @OrderBy("id DESC")
private Set<LoopLog> loopLogs = new HashSet<>();
public Loop() {
this.name = name;
}
- String getDcaeDeploymentId() {
+ public String getDcaeDeploymentId() {
return dcaeDeploymentId;
}
this.dcaeDeploymentId = dcaeDeploymentId;
}
- String getDcaeDeploymentStatusUrl() {
+ public String getDcaeDeploymentStatusUrl() {
return dcaeDeploymentStatusUrl;
}
this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
}
- String getSvgRepresentation() {
+ public String getSvgRepresentation() {
return svgRepresentation;
}
this.svgRepresentation = svgRepresentation;
}
- String getBlueprint() {
+ public String getBlueprint() {
return blueprint;
}
this.blueprint = blueprint;
}
- LoopState getLastComputedState() {
+ public LoopState getLastComputedState() {
return lastComputedState;
}
this.lastComputedState = lastComputedState;
}
- Set<OperationalPolicy> getOperationalPolicies() {
+ public Set<OperationalPolicy> getOperationalPolicies() {
return operationalPolicies;
}
this.operationalPolicies = operationalPolicies;
}
- Set<MicroServicePolicy> getMicroServicePolicies() {
+ public Set<MicroServicePolicy> getMicroServicePolicies() {
return microServicePolicies;
}
this.microServicePolicies = microServicePolicies;
}
- JsonObject getGlobalPropertiesJson() {
+ public JsonObject getGlobalPropertiesJson() {
return globalPropertiesJson;
}
this.globalPropertiesJson = globalPropertiesJson;
}
- Set<LoopLog> getLoopLogs() {
+ public Set<LoopLog> getLoopLogs() {
return loopLogs;
}
log.setLoop(this);
}
- String getDcaeBlueprintId() {
+ public String getDcaeBlueprintId() {
return dcaeBlueprintId;
}
this.dcaeBlueprintId = dcaeBlueprintId;
}
- JsonObject getModelPropertiesJson() {
+ public JsonObject getModelPropertiesJson() {
return modelPropertiesJson;
}
return buffer.toString().replace('.', '_').replaceAll(" ", "");
}
+ /**
+ * Generates the Json that must be sent to policy to add all policies to Active
+ * PDP group.
+ *
+ * @return The json, payload to send
+ */
+ public String createPoliciesPayloadPdpGroup() {
+ JsonObject jsonObject = new JsonObject();
+ JsonArray jsonArray = new JsonArray();
+ jsonObject.add("policies", jsonArray);
+
+ for (String policyName : this.listPolicyNamesPdpGroup()) {
+ JsonObject policyNode = new JsonObject();
+ jsonArray.add(policyNode);
+ policyNode.addProperty("policy-id", policyName);
+ }
+ String payload = new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject);
+ logger.info("PdpGroup policy payload: " + payload);
+ return payload;
+ }
+
+ /**
+ * Generates the list of policy names that must be send/remove to/from active
+ * PDP group.
+ *
+ * @return A list of policy names
+ */
+ public List<String> listPolicyNamesPdpGroup() {
+ List<String> policyNamesList = new ArrayList<>();
+ for (OperationalPolicy opPolicy : this.getOperationalPolicies()) {
+ policyNamesList.add(opPolicy.getName());
+ for (String guardName : opPolicy.createGuardPolicyPayloads().keySet()) {
+ policyNamesList.add(guardName);
+ }
+ }
+ for (MicroServicePolicy microServicePolicy : this.getMicroServicePolicies()) {
+ policyNamesList.add(microServicePolicy.getName());
+ }
+ return policyNamesList;
+ }
+
@Override
public int hashCode() {
final int prime = 31;