diff options
author | Hengye <yehui.wang@est.tech> | 2019-03-25 14:32:21 +0000 |
---|---|---|
committer | Hengye <yehui.wang@est.tech> | 2019-03-25 14:32:21 +0000 |
commit | b150aa8197e8a21ab7ad4cf1d91cfa30f56fa3df (patch) | |
tree | 60c296267f496f3b40d838294e8f80b04ceb2607 /models-interactions/model-impl/events | |
parent | 2a245ef80e39a101015efb164de53f1753fa5d47 (diff) |
migrate model-impl from drools-applications
migrate controlloop/common/model-impl from drools-applicaitons to
policy/models
Issue-ID: POLICY-1264
Change-Id: Ibe0bb5c49a7b1344f4104b30455f52834041e187
Signed-off-by: Hengye <yehui.wang@est.tech>
Diffstat (limited to 'models-interactions/model-impl/events')
28 files changed, 2238 insertions, 0 deletions
diff --git a/models-interactions/model-impl/events/README.md b/models-interactions/model-impl/events/README.md new file mode 100644 index 000000000..6ebd725d2 --- /dev/null +++ b/models-interactions/model-impl/events/README.md @@ -0,0 +1,11 @@ +Copyright 2018 AT&T Intellectual Property. All rights reserved. +This file is licensed under the CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE +Full license text at https://creativecommons.org/licenses/by/4.0/legalcode + +Policy Control Loop + +This is the implementation of the Policy's Control Loop messages. This includes the Events consumed and Notifications produced by the ONAP Policy Platform. + + + + diff --git a/models-interactions/model-impl/events/pom.xml b/models-interactions/model-impl/events/pom.xml new file mode 100644 index 000000000..ca079e00a --- /dev/null +++ b/models-interactions/model-impl/events/pom.xml @@ -0,0 +1,46 @@ +<!-- + ============LICENSE_START======================================================= + events in model-impl + ================================================================================ + Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>events</artifactId> + + <dependencies> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java new file mode 100644 index 000000000..37d7538c6 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java @@ -0,0 +1,193 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import com.google.gson.annotations.SerializedName; +import java.io.Serializable; +import java.util.UUID; + +public abstract class ControlLoopEvent implements Serializable { + + private static final long serialVersionUID = 2391252138583119195L; + + @SerializedName("closedLoopControlName") + private String closedLoopControlName; + + @SerializedName("version") + private String version = "1.0.2"; + + @SerializedName("requestID") + private UUID requestId; + + @SerializedName("closedLoopEventClient") + private String closedLoopEventClient; + + @SerializedName("target_type") + private ControlLoopTargetType targetType; + + @SerializedName("target") + private String target; + + @SerializedName("from") + private String from; + + @SerializedName("policyScope") + private String policyScope; + + @SerializedName("policyName") + private String policyName; + + @SerializedName("policyVersion") + private String policyVersion; + + @SerializedName("closedLoopEventStatus") + private ControlLoopEventStatus closedLoopEventStatus; + + @SerializedName("payload") + private String payload; + + public ControlLoopEvent() { + + } + + /** + * Construct an instace from an existing instance. + * + * @param event the existing instance + */ + public ControlLoopEvent(ControlLoopEvent event) { + if (event == null) { + return; + } + this.closedLoopControlName = event.closedLoopControlName; + this.requestId = event.requestId; + this.closedLoopEventClient = event.closedLoopEventClient; + this.targetType = event.targetType; + this.target = event.target; + this.from = event.from; + this.policyScope = event.policyScope; + this.policyName = event.policyName; + this.policyVersion = event.policyVersion; + this.closedLoopEventStatus = event.closedLoopEventStatus; + this.payload = event.payload; + } + + public boolean isEventStatusValid() { + return this.closedLoopEventStatus != null; + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public String getClosedLoopEventClient() { + return closedLoopEventClient; + } + + public void setClosedLoopEventClient(String closedLoopEventClient) { + this.closedLoopEventClient = closedLoopEventClient; + } + + public ControlLoopTargetType getTargetType() { + return targetType; + } + + public void setTargetType(ControlLoopTargetType targetType) { + this.targetType = targetType; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public ControlLoopEventStatus getClosedLoopEventStatus() { + return closedLoopEventStatus; + } + + public void setClosedLoopEventStatus(ControlLoopEventStatus closedLoopEventStatus) { + this.closedLoopEventStatus = closedLoopEventStatus; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEventStatus.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEventStatus.java new file mode 100644 index 000000000..961a4f8f2 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEventStatus.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +public enum ControlLoopEventStatus { + ONSET("ONSET"), ABATED("ABATED"); + + private String status; + + private ControlLoopEventStatus(String status) { + this.status = status; + } + + @Override + public String toString() { + return this.status; + } + + /** + * Convert a String status to a ControlLoopEventStatus. + * + * @param status the String status + * @return the ControlLoopEventStatus + */ + 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 ("abatement".equalsIgnoreCase(status)) { + return ABATED; + } + return null; + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java new file mode 100644 index 000000000..a55c65e2f --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java @@ -0,0 +1,191 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.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; + + private String closedLoopControlName; + private String version = "1.0.2"; + private UUID requestId; + private String closedLoopEventClient; + private ControlLoopTargetType targetType; + private String target; + private String from; + private String policyScope; + private String policyName; + private String policyVersion; + private ControlLoopNotificationType notification; + private String message; + private ZonedDateTime notificationTime = ZonedDateTime.now(ZoneOffset.UTC); + private Integer opsClTimer; + private List<ControlLoopOperation> history = new LinkedList<>(); + + public ControlLoopNotification() { + + } + + /** + * Construct an instance. + * + * @param event the event + */ + public ControlLoopNotification(ControlLoopEvent event) { + if (event == null) { + return; + } + + this.setClosedLoopControlName(event.getClosedLoopControlName()); + this.setRequestId(event.getRequestId()); + this.setClosedLoopEventClient(event.getClosedLoopEventClient()); + this.setTargetType(event.getTargetType()); + this.setTarget(event.getTarget()); + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public String getClosedLoopEventClient() { + return closedLoopEventClient; + } + + public void setClosedLoopEventClient(String closedLoopEventClient) { + this.closedLoopEventClient = closedLoopEventClient; + } + + public ControlLoopTargetType getTargetType() { + return targetType; + } + + public void setTargetType(ControlLoopTargetType targetType) { + this.targetType = targetType; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public ControlLoopNotificationType getNotification() { + return notification; + } + + public void setNotification(ControlLoopNotificationType notification) { + this.notification = notification; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public ZonedDateTime getNotificationTime() { + return notificationTime; + } + + public void setNotificationTime(ZonedDateTime notificationTime) { + this.notificationTime = notificationTime; + } + + public Integer getOpsClTimer() { + return opsClTimer; + } + + public void setOpsClTimer(Integer opsClTimer) { + this.opsClTimer = opsClTimer; + } + + public List<ControlLoopOperation> getHistory() { + return history; + } + + public void setHistory(List<ControlLoopOperation> history) { + this.history = history; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotificationType.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotificationType.java new file mode 100644 index 000000000..51df8749d --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotificationType.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.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; + } + + @Override + public String toString() { + return this.type; + } + + /** + * Convert a String type to a ControlLoopNotificationType. + * + * @param type the String type + * @return the ControlLoopNotificationType + */ + 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/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java new file mode 100644 index 000000000..8fd4148ef --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java @@ -0,0 +1,230 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import java.io.Serializable; +import java.time.Instant; + +public class ControlLoopOperation implements Serializable { + + private static final long serialVersionUID = 8662706581293017099L; + + private String actor; + private String operation; + private String target; + private Instant start = Instant.now(); + private Instant end; + private String subRequestId; + private String outcome; + private String message; + + public ControlLoopOperation() { + + } + + /** + * Construct an instance from an existing instance. + * + * @param op the existing instance + */ + public ControlLoopOperation(ControlLoopOperation op) { + if (op == null) { + return; + } + + 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; + } + + public String getActor() { + return actor; + } + + public void setActor(String actor) { + this.actor = actor; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public Instant getStart() { + return start; + } + + public void setStart(Instant start) { + this.start = start; + } + + public Instant getEnd() { + return end; + } + + public void setEnd(Instant end) { + this.end = end; + } + + public String getSubRequestId() { + return subRequestId; + } + + public void setSubRequestId(String subRequestId) { + this.subRequestId = subRequestId; + } + + public String getOutcome() { + return outcome; + } + + public void setOutcome(String outcome) { + this.outcome = outcome; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.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/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java new file mode 100644 index 000000000..35f482104 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import java.util.UUID; + +public class ControlLoopOperationWrapper { + + private UUID requestId; + private ControlLoopOperation operation; + + public ControlLoopOperationWrapper() { + + } + + public ControlLoopOperationWrapper(UUID requestId, ControlLoopOperation operation) { + this.requestId = requestId; + this.operation = operation; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public ControlLoopOperation getOperation() { + return operation; + } + + public void setOperation(ControlLoopOperation operation) { + this.operation = operation; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopTargetType.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopTargetType.java new file mode 100644 index 000000000..e1d107be4 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopTargetType.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +public enum ControlLoopTargetType { + VM("VM"), VF("VF"), VFC("VFC"), VNF("VNF"); + + private String type; + + private ControlLoopTargetType(String type) { + this.type = type; + } + + @Override + public String toString() { + return this.type; + } + + /** + * Convert a String type to a ControlLoopTargetType. + * + * @param type the String type + * @return the ControlLoopTargetType + */ + 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 (VNF.toString().equals(type)) { + return VNF; + } + + return null; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java new file mode 100644 index 000000000..245e3a6bd --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +public class PhysicalControlLoopEvent extends ControlLoopEvent { + private static final long serialVersionUID = -7282930271094849487L; + + public PhysicalControlLoopEvent() {} + + /** + * Construct an instance from an existing instance. + * + * @param event the existing instance + */ + public PhysicalControlLoopEvent(PhysicalControlLoopEvent event) { + super(event); + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java new file mode 100644 index 000000000..a76b807f4 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +public class PhysicalControlLoopNotification extends ControlLoopNotification { + private static final long serialVersionUID = 8105197217140032892L; + + public PhysicalControlLoopNotification() {} + + /** + * Construct an instance from an existing instance. + * + * @param event the existing instance + */ + public PhysicalControlLoopNotification(PhysicalControlLoopEvent event) { + super(event); + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java new file mode 100644 index 000000000..1223d564c --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import com.google.gson.annotations.SerializedName; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +public class VirtualControlLoopEvent extends ControlLoopEvent { + + private static final long serialVersionUID = -5752405682246066226L; + + @SerializedName("closedLoopAlarmStart") + private Instant closedLoopAlarmStart; + + @SerializedName("closedLoopAlarmEnd") + private Instant closedLoopAlarmEnd; + + @SerializedName("AAI") + private Map<String, String> aai = new HashMap<>(); + + public VirtualControlLoopEvent() {} + + + /** + * Construct an instance from an existing instance. + * + * @param event the existing instance + */ + public VirtualControlLoopEvent(VirtualControlLoopEvent event) { + super(event); + if (event == null) { + return; + } + if (event.aai != null) { + this.aai = new HashMap<>(event.aai); + } + this.closedLoopAlarmStart = event.closedLoopAlarmStart; + this.closedLoopAlarmEnd = event.closedLoopAlarmEnd; + } + + public Instant getClosedLoopAlarmStart() { + return closedLoopAlarmStart; + } + + public void setClosedLoopAlarmStart(Instant closedLoopAlarmStart) { + this.closedLoopAlarmStart = closedLoopAlarmStart; + } + + public Instant getClosedLoopAlarmEnd() { + return closedLoopAlarmEnd; + } + + public void setClosedLoopAlarmEnd(Instant closedLoopAlarmEnd) { + this.closedLoopAlarmEnd = closedLoopAlarmEnd; + } + + public Map<String, String> getAai() { + return aai; + } + + public void setAai(Map<String, String> aai) { + this.aai = aai; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java new file mode 100644 index 000000000..0a7436520 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import com.google.gson.annotations.SerializedName; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +public class VirtualControlLoopNotification extends ControlLoopNotification { + + private static final long serialVersionUID = 5354756047932144017L; + + @SerializedName("AAI") + private Map<String, String> aai = new HashMap<>(); + + @SerializedName("closedLoopAlarmStart") + private Instant closedLoopAlarmStart; + + @SerializedName("closedLoopAlarmEnd") + private Instant closedLoopAlarmEnd; + + public VirtualControlLoopNotification() {} + + /** + * Construct an instance. + * + * @param event the event + */ + public VirtualControlLoopNotification(VirtualControlLoopEvent event) { + super(event); + if (event == null) { + return; + } + if (event.getAai() != null) { + this.setAai(new HashMap<>(event.getAai())); + } + this.closedLoopAlarmStart = event.getClosedLoopAlarmStart(); + this.closedLoopAlarmEnd = event.getClosedLoopAlarmEnd(); + } + + public Map<String, String> getAai() { + return aai; + } + + public void setAai(Map<String, String> aai) { + this.aai = aai; + } + + public Instant getClosedLoopAlarmStart() { + return closedLoopAlarmStart; + } + + public void setClosedLoopAlarmStart(Instant closedLoopAlarmStart) { + this.closedLoopAlarmStart = closedLoopAlarmStart; + } + + public Instant getClosedLoopAlarmEnd() { + return closedLoopAlarmEnd; + } + + public void setClosedLoopAlarmEnd(Instant closedLoopAlarmEnd) { + this.closedLoopAlarmEnd = closedLoopAlarmEnd; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java new file mode 100644 index 000000000..11b90af99 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * AppcLcmActorServiceProvider + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop.params; + +import java.io.Serializable; + +public class ControlLoopParams implements Serializable { + + private static final long serialVersionUID = 970755684770982776L; + + private String closedLoopControlName; + private String controlLoopYaml; + private String policyName; + private String policyScope; + private String policyVersion; + + public ControlLoopParams() { + super(); + } + + /** + * Construct an instance from an existing instance. + * + * @param params the existing instance + */ + public ControlLoopParams(ControlLoopParams params) { + this.closedLoopControlName = params.closedLoopControlName; + this.controlLoopYaml = params.controlLoopYaml; + this.policyName = params.policyName; + this.policyScope = params.policyScope; + this.policyVersion = params.policyVersion; + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getControlLoopYaml() { + return controlLoopYaml; + } + + public void setControlLoopYaml(String controlLoopYaml) { + this.controlLoopYaml = controlLoopYaml; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java new file mode 100644 index 000000000..b36ee7f6b --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop.util; + +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.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; +import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import org.onap.policy.controlloop.ControlLoopNotificationType; +import org.onap.policy.controlloop.ControlLoopTargetType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class Serialization { + public static final 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(); + + + public static final 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(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); + + private 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) { + 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) { + return ControlLoopTargetType.toType(json.getAsString()); + } + } + + public static class GsonUtcAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { + private static final Logger logger = LoggerFactory.getLogger(GsonUtcAdapter.class); + public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + + @Override + public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) { + try { + return ZonedDateTime.parse(element.getAsString(), format); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override + 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) { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + +} diff --git a/models-interactions/model-impl/events/src/main/resources/definitions.yaml b/models-interactions/model-impl/events/src/main/resources/definitions.yaml new file mode 100644 index 000000000..57b8c1f2e --- /dev/null +++ b/models-interactions/model-impl/events/src/main/resources/definitions.yaml @@ -0,0 +1,128 @@ +# Copyright 2018 AT&T Intellectual Property. All rights reserved +# Modifications Copyright (C) 2019 Nordix Foundation. +# +# 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. +AAI: + type: object + properties: + AICVServerSelfLink: + type: string + VNF_NAME: + type: string + AICVMID: + type: string + AICTenantID: + type: string + LOC_ID: + type: string + in_maint: + type: boolean + AICIdentity: + type: string + Prov_status: + type: string + OAM_IPV4: + type: string + is_closed_loop_disabled: + type: boolean + VM_NAME: + type: string + OAM_IPV6: + type: string + required: + - AICVServerSelfLink + - AICIdentity + - is_closed_loop_disabled +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. + serviceInstance: + $ref: '../../../../sdc/src/main/resources/definitions.yaml#/serviceInstance' + resourceInstance: + $ref: '../../../../sdc/src/main/resources/definitions.yaml#/resourceInstance' + requestID: + type: string + description: This is required via ONAP 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}/ + triggerID: + type: string + description: ID that maps back to Highland Park. Concatenation between eventID and firstEPOCH. + triggerSourceName: + type: string + description: pulled from eventSourceName of trigger H.P. alarm. The contents of this field should also be contained in the AAI Json sub-tag (see below). + closedLoopAlarmStart: + type: string + description: firstEpoch. UTC Timestamp when this event was detected by DCAE. Conform to ONAP Logging requirements. + closedLoopAlarmEnd: + type: string + description: lastEpoch. UTC Timestamp when this event was detected as cleared by DCAE. Conform to ONAP 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: + $ref: '#/AAI' + from: + type: string + policyScope: + type: string + policyName: + type: string + policyVersion: + type: string + required: + - closedLoopControlName + - requestID + - triggerID + - triggerSourceName + - 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 diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventStatusTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventStatusTest.java new file mode 100644 index 000000000..f890cfce8 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventStatusTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; + +public class ControlLoopEventStatusTest { + + @Test + public void test() { + ControlLoopEventStatus status = ControlLoopEventStatus.ABATED; + assertEquals(ControlLoopEventStatus.ABATED, ControlLoopEventStatus.toStatus(status.toString())); + assertNotEquals(ControlLoopEventStatus.ONSET, ControlLoopEventStatus.toStatus(status.toString())); + + status = ControlLoopEventStatus.ONSET; + assertEquals(ControlLoopEventStatus.ONSET, ControlLoopEventStatus.toStatus(status.toString())); + assertNotEquals(ControlLoopEventStatus.ABATED, ControlLoopEventStatus.toStatus(status.toString())); + assertEquals(ControlLoopEventStatus.ABATED, ControlLoopEventStatus.toStatus("abatement")); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventTest.java new file mode 100644 index 000000000..feaf22ee5 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventTest.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; +import org.junit.Test; + +public class ControlLoopEventTest { + + private class TestControlLoopEvent extends ControlLoopEvent { + private static final long serialVersionUID = 1L; + + public TestControlLoopEvent() { + super(); + } + + public TestControlLoopEvent(ControlLoopEvent event) { + super(event); + } + } + + @Test + public void test() { + ControlLoopEvent event = new TestControlLoopEvent(); + + assertEquals("1.0.2", event.getVersion()); + + event = new TestControlLoopEvent(null); + assertEquals("1.0.2", event.getVersion()); + + event.setClosedLoopControlName("name"); + assertEquals("name", event.getClosedLoopControlName()); + + event.setClosedLoopEventClient("client"); + assertEquals("client", event.getClosedLoopEventClient()); + + event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + assertEquals(ControlLoopEventStatus.ONSET, event.getClosedLoopEventStatus()); + + event.setFrom("from"); + assertEquals("from", event.getFrom()); + + event.setPayload("payload"); + assertEquals("payload", event.getPayload()); + + event.setPolicyName("policyname"); + assertEquals("policyname", event.getPolicyName()); + + event.setPolicyScope("scope"); + assertEquals("scope", event.getPolicyScope()); + + event.setPolicyVersion("1"); + assertEquals("1", event.getPolicyVersion()); + + UUID id = UUID.randomUUID(); + event.setRequestId(id); + assertEquals(id, event.getRequestId()); + + event.setTarget("target"); + assertEquals("target", event.getTarget()); + + event.setTargetType(ControlLoopTargetType.VF); + assertEquals(ControlLoopTargetType.VF, event.getTargetType()); + + event.setVersion("foo"); + assertEquals("foo", event.getVersion()); + + ControlLoopEvent event2 = new TestControlLoopEvent(event); + assertTrue(event2.isEventStatusValid()); + + event2.setClosedLoopEventStatus(null); + assertFalse(event2.isEventStatusValid()); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTest.java new file mode 100644 index 000000000..0c1070e44 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTest.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Collections; +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.controlloop.util.Serialization; + +public class ControlLoopNotificationTest { + + private class TestControlLoopNotification extends ControlLoopNotification { + private static final long serialVersionUID = 1L; + + public TestControlLoopNotification() { + super(); + } + + public TestControlLoopNotification(ControlLoopEvent event) { + super(event); + } + } + + @Test + public void test() { + ControlLoopNotification notification = new TestControlLoopNotification(); + + assertEquals("1.0.2", notification.getVersion()); + + notification.setClosedLoopControlName("name"); + assertEquals("name", notification.getClosedLoopControlName()); + + notification.setClosedLoopEventClient("client"); + assertEquals("client", notification.getClosedLoopEventClient()); + + notification.setFrom("from"); + assertEquals("from", notification.getFrom()); + + notification.setHistory(Collections.emptyList()); + assertTrue(notification.getHistory().size() == 0); + + notification.setMessage("message"); + assertEquals("message", notification.getMessage()); + + notification.setNotification(ControlLoopNotificationType.ACTIVE); + assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); + + ZonedDateTime time = ZonedDateTime.now(ZoneOffset.UTC); + notification.setNotificationTime(time); + assertEquals(time, notification.getNotificationTime()); + + notification.setOpsClTimer(Integer.valueOf(1000)); + assertEquals(Integer.valueOf(1000), notification.getOpsClTimer()); + + notification.setPolicyName("name"); + assertEquals("name", notification.getPolicyName()); + + notification.setPolicyScope("scope"); + assertEquals("scope", notification.getPolicyScope()); + + notification.setPolicyVersion("1"); + assertEquals("1", notification.getPolicyVersion()); + + UUID id = UUID.randomUUID(); + notification.setRequestId(id); + assertEquals(id, notification.getRequestId()); + + notification.setTarget("target"); + assertEquals("target", notification.getTarget()); + + notification.setTargetType(ControlLoopTargetType.VFC); + assertEquals(ControlLoopTargetType.VFC, notification.getTargetType()); + + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.setClosedLoopControlName("controlloop"); + + TestControlLoopNotification notification2 = new TestControlLoopNotification(event); + assertEquals("controlloop", notification2.getClosedLoopControlName()); + + notification2.setVersion("1"); + assertEquals("1", notification2.getVersion()); + + String json = Serialization.gsonPretty.toJson(notification); + + TestControlLoopNotification notification3 = Serialization.gson.fromJson(json, + TestControlLoopNotification.class); + + // + // There is no equals for the class - chose not to create one + // + assertEquals(notification.getRequestId(), notification3.getRequestId()); + + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTypeTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTypeTest.java new file mode 100644 index 000000000..a8330ba2e --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTypeTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class ControlLoopNotificationTypeTest { + + @Test + public void test() { + + assertEquals(ControlLoopNotificationType.ACTIVE, ControlLoopNotificationType.toType("ACTIVE")); + assertEquals(ControlLoopNotificationType.REJECTED, ControlLoopNotificationType.toType("REJECTED")); + assertEquals(ControlLoopNotificationType.OPERATION, ControlLoopNotificationType.toType("OPERATION")); + assertEquals(ControlLoopNotificationType.OPERATION_SUCCESS, + ControlLoopNotificationType.toType("OPERATION: SUCCESS")); + assertEquals(ControlLoopNotificationType.OPERATION_FAILURE, + ControlLoopNotificationType.toType("OPERATION: FAILURE")); + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, + ControlLoopNotificationType.toType("FINAL: FAILURE")); + assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, + ControlLoopNotificationType.toType("FINAL: SUCCESS")); + assertEquals(ControlLoopNotificationType.FINAL_OPENLOOP, + ControlLoopNotificationType.toType("FINAL: OPENLOOP")); + + assertNull(ControlLoopNotificationType.toType("foo")); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java new file mode 100644 index 000000000..eb1a351d1 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import org.junit.Test; + +public class ControlLoopOperationTest { + + @Test + public void test() { + ControlLoopOperation operation = new ControlLoopOperation(); + + assertEquals(operation, operation); + assertNotEquals(operation, new String()); + assertNotEquals(operation, null); + + assertTrue(operation.hashCode() != 0); + assertTrue(operation.toString().startsWith("ControlLoopOperation")); + + assertNotNull(operation); + + operation.setActor("actor"); + assertEquals("actor", operation.getActor()); + + operation.setOperation("operation"); + assertEquals("operation", operation.getOperation()); + + Instant now = Instant.now(); + operation.setStart(now); + assertEquals(now, operation.getStart()); + operation.setEnd(now); + assertEquals(now, operation.getEnd()); + + operation.setMessage("message"); + assertEquals("message", operation.getMessage()); + + operation.setOutcome("outcome"); + assertEquals("outcome", operation.getOutcome()); + + operation.setSubRequestId("1"); + assertEquals("1", operation.getSubRequestId()); + + operation.setTarget("target"); + assertEquals("target", operation.getTarget()); + + assertTrue(operation.hashCode() != 0); + + ControlLoopOperation operation2 = new ControlLoopOperation(operation); + assertEquals(now, operation2.getEnd()); + + assertEquals(operation, operation2); + + operation2.setActor("foo"); + assertNotEquals(operation, operation2); + + operation = new ControlLoopOperation(null); + assertNotNull(operation.getStart()); + + assertNotEquals(operation, operation2); + + assertTrue(operation.toMessage().startsWith("actor=")); + assertTrue(operation.toHistory().startsWith("actor=")); + + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationWrapperTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationWrapperTest.java new file mode 100644 index 000000000..46fd9de96 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationWrapperTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; +import org.junit.Test; + +public class ControlLoopOperationWrapperTest { + + @Test + public void test() { + ControlLoopOperationWrapper wrapper = new ControlLoopOperationWrapper(); + + assertNotNull(wrapper); + + ControlLoopOperation operation = new ControlLoopOperation(); + wrapper.setOperation(operation); + UUID id = UUID.randomUUID(); + wrapper.setRequestId(id); + + ControlLoopOperationWrapper wrapper2 = new ControlLoopOperationWrapper(wrapper.getRequestId(), + wrapper.getOperation()); + + assertEquals(operation, wrapper2.getOperation()); + assertEquals(id, wrapper2.getRequestId()); + + + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java new file mode 100644 index 000000000..d1412fe49 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class ControlLoopTargetTypeTest { + + @Test + public void test() { + assertEquals(ControlLoopTargetType.VM, ControlLoopTargetType.toType("VM")); + assertEquals(ControlLoopTargetType.VF, ControlLoopTargetType.toType("VF")); + assertEquals(ControlLoopTargetType.VFC, ControlLoopTargetType.toType("VFC")); + assertEquals(ControlLoopTargetType.VNF, ControlLoopTargetType.toType("VNF")); + + assertNull(ControlLoopTargetType.toType("foo")); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopEventTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopEventTest.java new file mode 100644 index 000000000..80f043e6b --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopEventTest.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class PhysicalControlLoopEventTest { + + @Test + public void test() { + PhysicalControlLoopEvent event = new PhysicalControlLoopEvent(); + assertNotNull(event); + + PhysicalControlLoopEvent event2 = new PhysicalControlLoopEvent(event); + assertNotNull(event2); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopNotificationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopNotificationTest.java new file mode 100644 index 000000000..f52bbc9bf --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopNotificationTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class PhysicalControlLoopNotificationTest { + + @Test + public void test() { + PhysicalControlLoopNotification notification = new PhysicalControlLoopNotification(); + assertNotNull(notification); + + PhysicalControlLoopNotification notification2 = new PhysicalControlLoopNotification( + new PhysicalControlLoopEvent()); + assertNotNull(notification2); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopEventTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopEventTest.java new file mode 100644 index 000000000..2acd3038c --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopEventTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.time.Instant; +import org.junit.Test; + +public class VirtualControlLoopEventTest { + + @Test + public void test() { + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + + assertNotNull(event); + assertNotNull(event.getAai()); + + Instant now = Instant.now(); + event.setClosedLoopAlarmStart(now); + event.setClosedLoopAlarmEnd(now); + + VirtualControlLoopEvent event2 = new VirtualControlLoopEvent(event); + assertEquals(now, event2.getClosedLoopAlarmStart()); + + event = new VirtualControlLoopEvent(null); + assertNull(event.getClosedLoopAlarmStart()); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopNotificationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopNotificationTest.java new file mode 100644 index 000000000..2ab622230 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopNotificationTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.util.Collections; +import org.junit.Test; + +public class VirtualControlLoopNotificationTest { + + @Test + public void test() { + VirtualControlLoopNotification notification = new VirtualControlLoopNotification(); + assertNotNull(notification); + + notification.setAai(Collections.emptyMap()); + assertTrue(notification.getAai().isEmpty()); + + Instant now = Instant.now(); + notification.setClosedLoopAlarmStart(now); + + notification.setClosedLoopAlarmEnd(now); + + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + + Instant later = Instant.now(); + event.setAai(Collections.emptyMap()); + event.setClosedLoopAlarmStart(later); + event.setClosedLoopAlarmEnd(later); + + notification = new VirtualControlLoopNotification(event); + assertEquals(later, notification.getClosedLoopAlarmStart()); + assertEquals(later, notification.getClosedLoopAlarmEnd()); + + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java new file mode 100644 index 000000000..bf23e5706 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.onap.policy.controlloop.params; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class ControlLoopParamsTest { + + @Test + public void test() { + ControlLoopParams params = new ControlLoopParams(); + assertNotNull(params); + + params.setClosedLoopControlName("name"); + params.setControlLoopYaml("yaml"); + params.setPolicyName("name"); + params.setPolicyScope("scope"); + params.setPolicyVersion("1"); + + ControlLoopParams params2 = new ControlLoopParams(params); + + assertTrue(params2.getClosedLoopControlName().equals("name")); + assertTrue(params2.getControlLoopYaml().equals("yaml")); + assertTrue(params2.getPolicyName().equals("name")); + assertTrue(params2.getPolicyScope().equals("scope")); + assertTrue(params2.getPolicyVersion().equals("1")); + + } +} |