diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2020-01-14 22:48:45 -0600 |
---|---|---|
committer | jhh <jorge.hernandez-herrero@att.com> | 2020-01-16 08:44:53 -0600 |
commit | 08d766437dc19037f21b57578448748e013bc031 (patch) | |
tree | 1cccd9f08f5d342b160a32c8bcdff37968792c89 /models-interactions/model-impl/events/src/main | |
parent | b321d781b99a869e179b8003260f92969a81b43e (diff) |
Added Time agnostic Onset and Abated classes
These classes can be used for comparison of alarm skeletons
independently of the time at which they were produced.
Issue-ID: POLICY-2323
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: I85b9d6a429de56f056eb0a6caa9e4f90fbd68918
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'models-interactions/model-impl/events/src/main')
6 files changed, 264 insertions, 18 deletions
diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/Abated.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/Abated.java new file mode 100644 index 000000000..3488e3b6a --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/Abated.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 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.onap.policy.controlloop; + +import lombok.ToString; + +/** + * An ABATED event. + */ +@ToString(callSuper = true) +public class Abated extends VirtualControlLoopEvent { + private static final long serialVersionUID = -90742191326653587L; + + /** + * No arguments constructor. + */ + public Abated() { + super(); + setClosedLoopEventStatus(ControlLoopEventStatus.ABATED); + } + + /** + * Constructor from a VirtualControlLoop event. + */ + public Abated(VirtualControlLoopEvent event) { + super(event); + setClosedLoopEventStatus(ControlLoopEventStatus.ABATED); + } + + @Override + public void setClosedLoopEventStatus(ControlLoopEventStatus status) { + if (status != ControlLoopEventStatus.ABATED) { + throw new IllegalArgumentException("Not an ABATED event status"); + } + + super.setClosedLoopEventStatus(status); + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/CanonicalAbated.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/CanonicalAbated.java new file mode 100644 index 000000000..f1f2db3ff --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/CanonicalAbated.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 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.onap.policy.controlloop; + +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +/** + * An ABATED event that determines equality with other ABATED + * with only non-time dependent values. + */ + +@NoArgsConstructor +@ToString(callSuper = true) +public class CanonicalAbated extends Abated { + private static final long serialVersionUID = 284865663873284818L; + + public CanonicalAbated(VirtualControlLoopEvent event) { + super(event); + } + + @Override + public boolean equals(Object other) { + // see hashcode method notes + return EqualsBuilder.reflectionEquals( + this, other, "requestId", "closedLoopAlarmStart", "closedLoopAlarmEnd"); + } + + @Override + public int hashCode() { + // The reflection based implementation has been chosen + // for maintenance reasons, even though may incur in some + // performance overhead. The other possibility is to use + // Objects.hash(..) but will require to spell out all fields + // to be considered, which are many more than the exceptions, + // in addition this class would need to be updated as new fields + // are added. Other option to consider in the future is to + // restructure the class hierarchy. Note that could not use + // lombok annotations to exclude fields from superclasses. + return + HashCodeBuilder.reflectionHashCode( + this, "requestId", "closedLoopAlarmStart", "closedLoopAlarmEnd"); + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/CanonicalOnset.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/CanonicalOnset.java new file mode 100644 index 000000000..98aa433f2 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/CanonicalOnset.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 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.onap.policy.controlloop; + +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +/** + * An ONSET event that determines equality with other ONSET events + * with only non-time dependent values. + */ + +@NoArgsConstructor +@ToString(callSuper = true) +public class CanonicalOnset extends Onset { + private static final long serialVersionUID = 284865663873284818L; + + public CanonicalOnset(VirtualControlLoopEvent event) { + super(event); + } + + @Override + public boolean equals(Object other) { + // see hashcode method notes + return EqualsBuilder.reflectionEquals( + this, other, "requestId", "closedLoopAlarmStart", "closedLoopAlarmEnd"); + } + + @Override + public int hashCode() { + // The reflection based implementation has been chosen + // for maintenance reasons, even though may incur in some + // performance overhead. The other possibility is to use + // Objects.hash(..) but will require to spell out all fields + // to be considered, which are many more than the exceptions, + // in addition this class would need to be updated as new fields + // are added. Other option to consider in the future is to + // restructure the class hierarchy. Note that could not use + // lombok annotations to exclude fields from superclasses. + return + HashCodeBuilder.reflectionHashCode( + this, "requestId", "closedLoopAlarmStart", "closedLoopAlarmEnd"); + } + +} 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 index bbe902ac2..3106e3909 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * controlloop * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,19 +35,19 @@ public abstract class ControlLoopEvent implements Serializable { private static final long serialVersionUID = 2391252138583119195L; @SerializedName("requestID") - private UUID requestId; + protected UUID requestId; @SerializedName("target_type") - private String targetType; - private String closedLoopControlName; - private String version = "1.0.2"; - private String closedLoopEventClient; - private String target; - private String from; - private String policyScope; - private String policyName; - private String policyVersion; - private ControlLoopEventStatus closedLoopEventStatus; - private Map<String, String> additionalEventParams; + protected String targetType; + protected String closedLoopControlName; + protected String version = "1.0.2"; + protected String closedLoopEventClient; + protected String target; + protected String from; + protected String policyScope; + protected String policyName; + protected String policyVersion; + protected ControlLoopEventStatus closedLoopEventStatus; + protected Map<String, String> additionalEventParams; /** * Construct an instance from an existing instance. diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/Onset.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/Onset.java new file mode 100644 index 000000000..41a0ebab4 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/Onset.java @@ -0,0 +1,58 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 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.onap.policy.controlloop; + +import lombok.NonNull; +import lombok.ToString; + +/** + * An ONSET event. + */ + +@ToString(callSuper = true) +public class Onset extends VirtualControlLoopEvent { + private static final long serialVersionUID = -90742191326653587L; + + /** + * No arguments constructor. + */ + public Onset() { + super(); + setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + } + + /** + * Constructor from a VirtualControlLoop event. + */ + public Onset(@NonNull VirtualControlLoopEvent event) { + super(event); + setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + } + + @Override + public void setClosedLoopEventStatus(ControlLoopEventStatus status) { + if (status != ControlLoopEventStatus.ONSET) { + throw new IllegalArgumentException("Not an ONSET event status"); + } + + super.setClosedLoopEventStatus(status); + } +} 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 index 24cc81dcd..3319105ea 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * controlloop * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,19 +29,21 @@ import java.util.Map; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.ToString; @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor +@ToString(callSuper = true) public class VirtualControlLoopEvent extends ControlLoopEvent { private static final long serialVersionUID = -5752405682246066226L; @SerializedName("AAI") - private Map<String, String> aai = new HashMap<>(); - private String payload; - private Instant closedLoopAlarmStart; - private Instant closedLoopAlarmEnd; + protected Map<String, String> aai = new HashMap<>(); + protected String payload; + protected Instant closedLoopAlarmStart; + protected Instant closedLoopAlarmEnd; /** * Construct an instance from an existing instance. |