diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2017-02-14 19:49:32 -0500 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2017-02-14 19:52:21 -0500 |
commit | a6557b0429dbe94a3806be237d9ba5aa7c4b183c (patch) | |
tree | e84136dc5aeb5b1c4ec1065e99c45a5084f295c6 /controlloop | |
parent | a91087731b18dab019621d99827cf1f4bcb95d10 (diff) |
Initial OpenECOMP policy/drools-applications commt
Change-Id: I21c0edbf9b7f18dccd6bd4fe2a3287f3a68e6de0
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'controlloop')
14 files changed, 941 insertions, 0 deletions
diff --git a/controlloop/pom.xml b/controlloop/pom.xml new file mode 100644 index 000000000..47e18703f --- /dev/null +++ b/controlloop/pom.xml @@ -0,0 +1,46 @@ +<!-- + ============LICENSE_START======================================================= + Drools PDP Application Models + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + ================================================================================ + 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. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.openecomp.policy.drools-applications</groupId> + <artifactId>controlloop</artifactId> + + <parent> + <groupId>org.openecomp.policy.drools-applications</groupId> + <artifactId>drools-pdp-apps</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.5</version> + <scope>provided</scope> + </dependency> + </dependencies> +</project> diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopEvent.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopEvent.java new file mode 100644 index 000000000..d7fa04884 --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopEvent.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +import java.io.Serializable; +import java.util.UUID; + +public abstract class ControlLoopEvent implements Serializable { + + private static final long serialVersionUID = 2391252138583119195L; + + public String closedLoopControlName; + public String version = "1.0.2"; + public UUID requestID; + public String closedLoopEventClient; + public ControlLoopTargetType target_type; + public String target; + public String from; + public String policyScope; + public String policyName; + public String policyVersion; + public ControlLoopEventStatus closedLoopEventStatus; + + public ControlLoopEvent() { + + } + + public ControlLoopEvent(ControlLoopEvent event) { + if (event == null) { + return; + } + this.closedLoopControlName = event.closedLoopControlName; + this.requestID = event.requestID; + this.closedLoopEventClient = event.closedLoopEventClient; + this.target_type = event.target_type; + this.target = event.target; + this.from = event.from; + this.policyScope = event.policyScope; + this.policyName = event.policyName; + this.policyVersion = event.policyVersion; + this.closedLoopEventStatus = event.closedLoopEventStatus; + } + + public boolean isEventStatusValid() { + if (this.closedLoopEventStatus == null) { + return false; + } + return true; + } + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopEventStatus.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopEventStatus.java new file mode 100644 index 000000000..063a611b9 --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopEventStatus.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +public enum ControlLoopEventStatus { + ONSET("ONSET"), + ABATED("ABATED") + ; + + private String status; + + private ControlLoopEventStatus(String status) { + this.status = status; + } + + public String toString() { + return this.status; + } + + public static ControlLoopEventStatus toStatus(String status) { + if (ONSET.status.equalsIgnoreCase(status)) { + return ONSET; + } + if (ABATED.status.equalsIgnoreCase(status)) { + return ABATED; + } + // + // In case DCAE uses the old abatement + // + if (status.equalsIgnoreCase("abatement")) { + return ABATED; + } + return null; + } + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopNotification.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopNotification.java new file mode 100644 index 000000000..15c61a80a --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopNotification.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +import java.io.Serializable; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; + +public abstract class ControlLoopNotification implements Serializable { + + private static final long serialVersionUID = 7538596984567127915L; + + public String closedLoopControlName; + public String version = "1.0.2"; + public UUID requestID; + public String closedLoopEventClient; + public ControlLoopTargetType target_type; + public String target; + public String from; + public String policyScope; + public String policyName; + public String policyVersion; + public ControlLoopNotificationType notification; + public String message; + public ZonedDateTime notificationTime = ZonedDateTime.now(ZoneOffset.UTC);; + public Integer OPS_CL_timer; + public List<ControlLoopOperation> history = new LinkedList<ControlLoopOperation>(); + + public ControlLoopNotification() { + + } + + public ControlLoopNotification(ControlLoopEvent event) { + this.closedLoopControlName = event.closedLoopControlName; + this.requestID = event.requestID; + this.closedLoopEventClient = event.closedLoopEventClient; + this.target_type = event.target_type; + this.target = event.target; + } + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopNotificationType.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopNotificationType.java new file mode 100644 index 000000000..a5618df02 --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopNotificationType.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +public enum ControlLoopNotificationType { + ACTIVE("ACTIVE"), + REJECTED("REJECTED"), + OPERATION("OPERATION"), + OPERATION_SUCCESS("OPERATION: SUCCESS"), + OPERATION_FAILURE("OPERATION: FAILURE"), + FINAL_FAILURE("FINAL: FAILURE"), + FINAL_SUCCESS("FINAL: SUCCESS"), + FINAL_OPENLOOP("FINAL: OPENLOOP") + ; + + private String type; + + private ControlLoopNotificationType(String type) { + this.type = type; + } + + public String toString() { + return this.type; + } + + public static ControlLoopNotificationType toType(String type) { + if (ACTIVE.toString().equals(type)) { + return ACTIVE; + } + if (REJECTED.toString().equals(type)) { + return REJECTED; + } + if (OPERATION.toString().equals(type)) { + return OPERATION; + } + if (OPERATION_SUCCESS.toString().equals(type)) { + return OPERATION_SUCCESS; + } + if (OPERATION_FAILURE.toString().equals(type)) { + return OPERATION_FAILURE; + } + if (FINAL_FAILURE.toString().equals(type)) { + return FINAL_FAILURE; + } + if (FINAL_SUCCESS.toString().equals(type)) { + return FINAL_SUCCESS; + } + if (FINAL_OPENLOOP.toString().equals(type)) { + return FINAL_OPENLOOP; + } + return null; + } + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopOperation.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopOperation.java new file mode 100644 index 000000000..8925ee287 --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopOperation.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +import java.io.Serializable; +import java.time.Instant; + +public class ControlLoopOperation implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 8662706581293017099L; + + public String actor; + public String operation; + public String target; + public Instant start = Instant.now(); + public Instant end; + public String subRequestId; + public String outcome; + public String message; + + public ControlLoopOperation() { + + } + + public ControlLoopOperation(ControlLoopOperation op) { + this.actor = op.actor; + this.operation = op.operation; + this.target = op.target; + this.start = op.start; + this.end = op.end; + this.subRequestId = op.subRequestId; + this.outcome = op.outcome; + this.message = op.message; + } + + public String toMessage() { + return "actor="+actor+",operation="+operation+",target="+target+",subRequestId="+subRequestId; + } + + public String toHistory() { + return "actor="+actor+",operation="+operation+",target="+target+",start="+start+",end="+end+",subRequestId="+subRequestId+",outcome="+outcome+",message="+message; + } + + @Override + public String toString() { + return "ControlLoopOperation [actor=" + actor + ", operation=" + operation + ", target=" + target + ", start=" + + start + ", end=" + end + ", subRequestId=" + subRequestId + ", outcome=" + outcome + ", message=" + + message + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((actor == null) ? 0 : actor.hashCode()); + result = prime * result + ((end == null) ? 0 : end.hashCode()); + result = prime * result + ((message == null) ? 0 : message.hashCode()); + result = prime * result + ((operation == null) ? 0 : operation.hashCode()); + result = prime * result + ((outcome == null) ? 0 : outcome.hashCode()); + result = prime * result + ((start == null) ? 0 : start.hashCode()); + result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode()); + result = prime * result + ((target == null) ? 0 : target.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ControlLoopOperation other = (ControlLoopOperation) obj; + if (actor == null) { + if (other.actor != null) + return false; + } else if (!actor.equals(other.actor)) + return false; + if (end == null) { + if (other.end != null) + return false; + } else if (!end.equals(other.end)) + return false; + if (message == null) { + if (other.message != null) + return false; + } else if (!message.equals(other.message)) + return false; + if (operation == null) { + if (other.operation != null) + return false; + } else if (!operation.equals(other.operation)) + return false; + if (outcome == null) { + if (other.outcome != null) + return false; + } else if (!outcome.equals(other.outcome)) + return false; + if (start == null) { + if (other.start != null) + return false; + } else if (!start.equals(other.start)) + return false; + if (subRequestId == null) { + if (other.subRequestId != null) + return false; + } else if (!subRequestId.equals(other.subRequestId)) + return false; + if (target == null) { + if (other.target != null) + return false; + } else if (!target.equals(other.target)) + return false; + return true; + } + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopOperationWrapper.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopOperationWrapper.java new file mode 100644 index 000000000..417a59d8e --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopOperationWrapper.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +import java.util.UUID; + +public class ControlLoopOperationWrapper { + + public UUID requestID; + public ControlLoopOperation operation; + + public ControlLoopOperationWrapper() { + + } + + public ControlLoopOperationWrapper(UUID requestID, ControlLoopOperation operation) { + this.requestID = requestID; + this.operation = operation; + } +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopTargetType.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopTargetType.java new file mode 100644 index 000000000..c1ed0e1d8 --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/ControlLoopTargetType.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +public enum ControlLoopTargetType { + VM("VM"), + VF("VF"), + VFC("VFC"), + ENODEB("eNodeB") + ; + + private String type; + + private ControlLoopTargetType(String type) { + this.type = type; + } + + public String toString() { + return this.type; + } + + public static ControlLoopTargetType toType(String type) { + if (VM.toString().equals(type)) { + return VM; + } + if (VF.toString().equals(type)) { + return VF; + } + if (VFC.toString().equals(type)) { + return VFC; + } + if (ENODEB.toString().equals(type)) { + return ENODEB; + } + return null; + } +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/PhysicalControlLoopEvent.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/PhysicalControlLoopEvent.java new file mode 100644 index 000000000..615ee48bc --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/PhysicalControlLoopEvent.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +public class PhysicalControlLoopEvent extends ControlLoopEvent { + + /** + * + */ + private static final long serialVersionUID = -7282930271094849487L; + + public PhysicalControlLoopEvent() { + } + + public PhysicalControlLoopEvent(PhysicalControlLoopEvent event) { + super(event); + if (event == null) { + return; + } + } + + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/PhysicalControlLoopNotification.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/PhysicalControlLoopNotification.java new file mode 100644 index 000000000..ee093cb67 --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/PhysicalControlLoopNotification.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +public class PhysicalControlLoopNotification extends ControlLoopNotification { + + /** + * + */ + private static final long serialVersionUID = 8105197217140032892L; + + public PhysicalControlLoopNotification() { + } + + public PhysicalControlLoopNotification(PhysicalControlLoopEvent event) { + super(event); + if (event == null) { + return; + } + } + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/VirtualControlLoopEvent.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/VirtualControlLoopEvent.java new file mode 100644 index 000000000..6ca280e4a --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/VirtualControlLoopEvent.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +public class VirtualControlLoopEvent extends ControlLoopEvent { + + /** + * + */ + private static final long serialVersionUID = -5752405682246066226L; + public Instant closedLoopAlarmStart; + public Instant closedLoopAlarmEnd; + public Map<String, String> AAI = new HashMap<String, String>(); + + public VirtualControlLoopEvent() { + } + + public VirtualControlLoopEvent(VirtualControlLoopEvent event) { + super(event); + if (event == null) { + return; + } + if (event.AAI != null) { + this.AAI = new HashMap<String, String>(event.AAI); + } + this.closedLoopAlarmStart = event.closedLoopAlarmStart; + this.closedLoopAlarmEnd = event.closedLoopAlarmEnd; + } + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/VirtualControlLoopNotification.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/VirtualControlLoopNotification.java new file mode 100644 index 000000000..239a3ef21 --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/VirtualControlLoopNotification.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +public class VirtualControlLoopNotification extends ControlLoopNotification { + + /** + * + */ + private static final long serialVersionUID = 5354756047932144017L; + + public Map<String, String> AAI = new HashMap<String, String>(); + public Instant closedLoopAlarmStart; + public Instant closedLoopAlarmEnd; + + public VirtualControlLoopNotification() { + } + + public VirtualControlLoopNotification(VirtualControlLoopEvent event) { + super(event); + if (event == null) { + return; + } + if (event.AAI != null) { + this.AAI = new HashMap<String, String>(event.AAI); + } + this.closedLoopAlarmStart = event.closedLoopAlarmStart; + this.closedLoopAlarmEnd = event.closedLoopAlarmEnd; + } + +} diff --git a/controlloop/src/main/java/org/openecomp/policy/controlloop/util/Serialization.java b/controlloop/src/main/java/org/openecomp/policy/controlloop/util/Serialization.java new file mode 100644 index 000000000..2625da712 --- /dev/null +++ b/controlloop/src/main/java/org/openecomp/policy/controlloop/util/Serialization.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controlloop.util; + +import java.lang.reflect.Type; +import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import org.openecomp.policy.controlloop.ControlLoopNotificationType; +import org.openecomp.policy.controlloop.ControlLoopTargetType; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +public final class Serialization { + + public static class notificationTypeAdapter implements JsonSerializer<ControlLoopNotificationType>, JsonDeserializer<ControlLoopNotificationType> { + + @Override + public JsonElement serialize(ControlLoopNotificationType src, Type typeOfSrc, + JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + @Override + public ControlLoopNotificationType deserialize(JsonElement json, Type typeOfT, + JsonDeserializationContext context) throws JsonParseException { + return ControlLoopNotificationType.toType(json.getAsString()); + } + + } + + public static class targetTypeAdapter implements JsonSerializer<ControlLoopTargetType>, JsonDeserializer<ControlLoopTargetType> { + + @Override + public JsonElement serialize(ControlLoopTargetType src, Type typeOfSrc, + JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + @Override + public ControlLoopTargetType deserialize(JsonElement json, Type typeOfT, + JsonDeserializationContext context) throws JsonParseException { + return ControlLoopTargetType.toType(json.getAsString()); + } + + } + + public static class gsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { + public static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + + public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) + throws JsonParseException { + try { + return ZonedDateTime.parse(element.getAsString(), format); + } catch (Exception e) { + System.err.println(e); + } + return null; + } + + public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) { + return new JsonPrimitive(datetime.format(format)); + } + } + + public static class gsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + + final static public Gson gson = new GsonBuilder().disableHtmlEscaping() + .registerTypeAdapter(ZonedDateTime.class, new gsonUTCAdapter()) + .registerTypeAdapter(Instant.class, new gsonInstantAdapter()) + .registerTypeAdapter(ControlLoopNotificationType.class, new notificationTypeAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new targetTypeAdapter()) + .create(); + + + final static public Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() + .setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new gsonUTCAdapter()) + .registerTypeAdapter(Instant.class, new gsonInstantAdapter()) + .registerTypeAdapter(ControlLoopNotificationType.class, new notificationTypeAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new targetTypeAdapter()) + .create(); + +} diff --git a/controlloop/src/main/resources/definitions.yaml b/controlloop/src/main/resources/definitions.yaml new file mode 100644 index 000000000..13016ef5a --- /dev/null +++ b/controlloop/src/main/resources/definitions.yaml @@ -0,0 +1,96 @@ +### +# ============LICENSE_START======================================================= +# controlloop +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +ControlLoop: + type: object + description: Common fields for control loop events and notifications + properties: + closedLoopControlName: + type: string + description: A UNIQUE string identifying the Closed Loop ID this event is for. There are no semantics behind this string. + requestID: + type: string + description: This is required via ECOMP Platform Logging Requirements. + pattern: /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/ + closedLoopAlarmStart: + type: string + description: firstEpoch. UTC Timestamp when this event was detected by DCAE. Conform to ECOMP Logging requirements. + closedLoopAlarmEnd: + type: string + description: lastEpoch. UTC Timestamp when this event was detected as cleared by DCAE. Conform to ECOMP Logging requirements. + closedLoopEventClient: + type: string + description: Open DCAE sub-system that detected the event and published this event message. + target: + type: string + description: The target entity that is being administered. This could be VM_NAME, VNF_NAME, etc. This should map to a field name in the AAI sub-tag shown below. + AAI: + type: object + description: Fields of node.attribute and their values that map to AAI topology. + from: + type: string + description: The ECOMP component generating this message. + policyScope: + type: string + description: The policy scope driving the generation of this message. + policyName: + type: string + description: The policy name driving the generation of this message. + policyVersion: + type: string + description: The policy version driving the generation of this message. + required: + - closedLoopControlName + - requestID + - closedLoopAlarmStart + - closedLoopEventClient + - target + - AAI + - from + - policyScope + - policyName + - policyVersion +Event: + allOf: + - $ref: '#/ControlLoop' + - properties: + closedLoopEventStatus: + type: string + description: The status for the event within Open DCAE. A value of “ONSET� indicates the event has been encountered. “ABATED� indicates the event has been abated. + valid_values: + - ONSET + - ABATEMENT + - required: + - closedLoopEventStatus +Notification: + - $ref: '#/ControlLoop' + - properties: + notification: + type: string + notificationTime: + type: string + message: + type: string + OPS_CL_timer: + type: int + - required: + - notification + - notificationTime + - OPS_CL_timer |