X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Floop%2FLoop.java;h=6de2863ea77b4b5e2456b7814ebb6675ab4ff4b9;hb=785b17789adc4817e129fcd389d91046b195044a;hp=83f938ddea40defe54a4153ee079dc1adf64539d;hpb=eb71d70552c827e1d8405862f73e8cbd827c6e48;p=clamp.git diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java index 83f938dd..6de2863e 100644 --- a/src/main/java/org/onap/clamp/loop/Loop.java +++ b/src/main/java/org/onap/clamp/loop/Loop.java @@ -23,13 +23,17 @@ 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; @@ -43,7 +47,9 @@ import javax.persistence.JoinColumn; 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; @@ -63,6 +69,9 @@ public class Loop implements Serializable { */ 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) @@ -112,6 +121,7 @@ public class Loop implements Serializable { @Expose @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop") + @OrderBy("id DESC") private Set loopLogs = new HashSet<>(); public Loop() { @@ -259,28 +269,45 @@ public class Loop implements Serializable { 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 (OperationalPolicy opPolicy : this.getOperationalPolicies()) { + for (String policyName : this.listPolicyNamesPdpGroup()) { JsonObject policyNode = new JsonObject(); jsonArray.add(policyNode); - policyNode.addProperty("policy-id", opPolicy.getName()); + 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 listPolicyNamesPdpGroup() { + List policyNamesList = new ArrayList<>(); + for (OperationalPolicy opPolicy : this.getOperationalPolicies()) { + policyNamesList.add(opPolicy.getName()); for (String guardName : opPolicy.createGuardPolicyPayloads().keySet()) { - JsonObject guardPolicyNode = new JsonObject(); - jsonArray.add(guardPolicyNode); - guardPolicyNode.addProperty("policy-id", guardName); + policyNamesList.add(guardName); } } for (MicroServicePolicy microServicePolicy : this.getMicroServicePolicies()) { - JsonObject policyNode = new JsonObject(); - jsonArray.add(policyNode); - policyNode.addProperty("policy-id", microServicePolicy.getName()); + policyNamesList.add(microServicePolicy.getName()); } - return new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject); + return policyNamesList; } @Override