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/sdnr/src/main | |
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/sdnr/src/main')
11 files changed, 1468 insertions, 0 deletions
diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java new file mode 100644 index 000000000..5c1ed4839 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java @@ -0,0 +1,265 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited 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.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class PciCommonHeader implements Serializable { + + private static final long serialVersionUID = 5435363539127062114L; + + @SerializedName(value = "TimeStamp") + private Instant timeStamp = Instant.now(); + + @SerializedName(value = "APIVer") + private String apiVer = "1.0"; + + @SerializedName(value = "RequestID") + private UUID requestId; + + @SerializedName(value = "SubRequestID") + private String subRequestId; + + @SerializedName(value = "RequestTrack") + private Map<String, String> requestTrack = new HashMap<>(); + + @SerializedName(value = "Flags") + private Map<String, String> flags = new HashMap<>(); + + public PciCommonHeader() { + + } + + /** + * Used to copy a pci common header. + * + * @param commonHeader a header that is defined by the Pci api guide that contains information + * about the request (requestId, flags, etc.) + */ + public PciCommonHeader(PciCommonHeader commonHeader) { + this.timeStamp = commonHeader.timeStamp; + this.requestId = commonHeader.requestId; + this.subRequestId = commonHeader.subRequestId; + if (commonHeader.requestTrack != null) { + this.requestTrack.putAll(commonHeader.requestTrack); + } + if (commonHeader.flags != null) { + this.flags.putAll(commonHeader.flags); + } + } + + /** + * Get the timestamp. + * + * @return the timeStamp + */ + public Instant getTimeStamp() { + return timeStamp; + } + + /** + * Set the timestamp. + * + * @param timeStamp + * the timeStamp to set + */ + public void setTimeStamp(Instant timeStamp) { + this.timeStamp = timeStamp; + } + + /** + * Get the API version. + * + * @return the apiVer + */ + public String getApiVer() { + return apiVer; + } + + /** + * Set the API version. + * + * @param apiVer + * the apiVer to set + */ + public void setApiVer(String apiVer) { + this.apiVer = apiVer; + } + + /** + * Get the request Id. + * + * @return the requestId + */ + public UUID getRequestId() { + return requestId; + } + + /** + * Set the request Id. + * + * @param requestId + * the requestId to set + */ + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + /** + * Get the sub request Id. + * + * @return the subRequestId + */ + public String getSubRequestId() { + return subRequestId; + } + + /** + * Set the sub request Id. + * + * @param subRequestId + * the subRequestId to set + */ + public void setSubRequestId(String subRequestId) { + this.subRequestId = subRequestId; + } + /** + * Set the request track. + * + * @param requestTrack + * the requestTrack to set + */ + public void setRequestTrack(Map<String, String> requestTrack) { + this.requestTrack = requestTrack; + } + /** + * Get the request track. + * + * @return the requestTrack + */ + public Map<String, String> getRequestTrack() { + return requestTrack; + } + + /** + * Get the flags. + * + * @return the flags + */ + public Map<String, String> getFlags() { + return flags; + } + + /** + * Set the flags. + * + * @param flags + * the flags to set + */ + public void setFlags(Map<String, String> flags) { + this.flags = flags; + } + + @Override + public String toString() { + return "CommonHeader [timeStamp=" + timeStamp + ", apiVer=" + apiVer + + ", requestId=" + requestId + ", subRequestId=" + subRequestId + ", requestTrack=" + requestTrack + + ", flags=" + flags + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode()); + result = prime * result + ((flags == null) ? 0 : flags.hashCode()); + result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode()); + result = prime * result + ((requestId == null) ? 0 : requestId.hashCode()); + result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode()); + result = prime * result + ((timeStamp == null) ? 0 : timeStamp.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; + } + PciCommonHeader other = (PciCommonHeader) obj; + if (apiVer == null) { + if (other.apiVer != null) { + return false; + } + } else if (!apiVer.equals(other.apiVer)) { + return false; + } + if (flags == null) { + if (other.flags != null) { + return false; + } + } else if (!flags.equals(other.flags)) { + return false; + } + if (requestTrack == null) { + if (other.requestTrack != null) { + return false; + } + } else if (!requestTrack.equals(other.requestTrack)) { + return false; + } + if (requestId == null) { + if (other.requestId != null) { + return false; + } + } else if (!requestId.equals(other.requestId)) { + return false; + } + if (subRequestId == null) { + if (other.subRequestId != null) { + return false; + } + } else if (!subRequestId.equals(other.subRequestId)) { + return false; + } + if (timeStamp == null) { + if (other.timeStamp != null) { + return false; + } + } else if (!timeStamp.equals(other.timeStamp)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java new file mode 100644 index 000000000..d7f979bc0 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited 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.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciRequest implements Serializable { + + private static final long serialVersionUID = 323235565922846624L; + + @SerializedName(value = "CommonHeader") + private PciCommonHeader commonHeader; + + @SerializedName(value = "Action") + private String action; + + @SerializedName(value = "Payload") + private String payload; + + public PciRequest() { + // Create a default PCI request + } + + public PciCommonHeader getCommonHeader() { + return commonHeader; + } + + public void setCommonHeader(PciCommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + /** + * Get the action. + * + * @return the action + */ + public String getAction() { + return action; + } + + /** + * Set the action. + * + * @param action + * the action to set + */ + public void setAction(String action) { + this.action = action; + } + + /** + * Get the payload. + * + * @return the payload + */ + + public String getPayload() { + return payload; + } + + /** + * Set the payload. + * + * @param action + * the action to set + */ + + public void setPayload(String payload) { + this.payload = payload; + } + + @Override + public String toString() { + return "PciRequest[commonHeader=" + commonHeader + ", action=" + action + ", payload=" + payload + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); + result = prime * result + ((action == null) ? 0 : action.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.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; + } + PciRequest other = (PciRequest) obj; + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + if (action == null) { + if (other.action != null) { + return false; + } + } else if (!action.equals(other.action)) { + return false; + } + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java new file mode 100644 index 000000000..b8ce925f2 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited 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.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciRequestWrapper extends PciWrapper implements Serializable { + + private static final long serialVersionUID = 879766924715980798L; + + @SerializedName(value = "body") + private PciRequest body; + + public PciRequestWrapper() { + super(); + } + + public PciRequestWrapper(PciRequest request) { + body = request; + } + + /** + * Get the body. + * + * @return the body + */ + public PciRequest getBody() { + return body; + } + + /** + * Set the body. + * + * @param body + * the body to set + */ + public void setBody(PciRequest body) { + this.body = body; + } + + @Override + public String toString() { + return "RequestWrapper [body=" + body + ", toString()=" + super.toString() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((body == null) ? 0 : body.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PciRequestWrapper other = (PciRequestWrapper) obj; + if (body == null) { + if (other.body != null) { + return false; + } + } else if (!body.equals(other.body)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java new file mode 100644 index 000000000..3cb4e8af6 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited 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.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciResponse implements Serializable { + + private static final long serialVersionUID = 8375708697287669750L; + + @SerializedName(value = "CommonHeader") + private PciCommonHeader commonHeader; + + @SerializedName(value = "Status") + private Status status = new Status(); + + @SerializedName(value = "Payload") + private String payload; + + public PciResponse() { + // EMPTY + } + + /** + * Constructs a response using the common header of the request since they will + * be the same. + * + * @param request + * an sdnr Pci request object specified by the Pci api guide + */ + public PciResponse(PciRequest request) { + this.commonHeader = new PciCommonHeader(request.getCommonHeader()); + + } + + /** + * Get the common header. + * + * @return the commonHeader + */ + public PciCommonHeader getCommonHeader() { + return commonHeader; + } + + /** + * Set the common header. + * + * @param commonHeader + * the commonHeader to set + */ + public void setCommonHeader(PciCommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + /** + * Get the status. + * + * @return the status + */ + public Status getStatus() { + return status; + } + + /** + * Set the status. + * + * @param status + * the status to set + */ + public void setStatus(Status status) { + this.status = status; + } + + /** + * Get the payload. + * + * @return the payload + */ + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + @Override + public String toString() { + return "PciResponse[CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + + payload + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.hashCode()); + result = prime * result + ((status == null) ? 0 : status.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; + } + PciResponse other = (PciResponse) obj; + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + return true; + } +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java new file mode 100644 index 000000000..35a85d779 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. + * 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.sdnr; + +import java.io.Serializable; +import org.onap.policy.sdnr.util.StatusCodeEnum; + +public class PciResponseCode implements Serializable { + + /* These fields define the key to the response code value. */ + public static final String ACCEPTED = "ACCEPTED"; + public static final String ERROR = "ERROR"; + public static final String REJECT = "REJECT"; + public static final String SUCCESS = "SUCCESS"; + public static final String FAILURE = "FAILURE"; + public static final String PARTIAL_SUCCESS = "PARTIAL SUCCESS"; + public static final String PARTIAL_FAILURE = "PARTIAL FAILURE"; + private static final long serialVersionUID = -5371924429933449763L; + + private final Integer code; + + protected PciResponseCode(final int code) { + this.code = code; + } + + public int getCode() { + return this.code; + } + + @Override + public String toString() { + return Integer.toString(this.code); + } + + /** + * Translates the code to a string value that represents the meaning of the code. + * + * @param code the numeric value that is returned by SDNR based on success, failure, etc. of the action requested + * @return the string value equivalent of the SDNR response code + */ + public static String toResponseValue(int code) { + StatusCodeEnum statusCodeEnum = StatusCodeEnum.fromStatusCode(code); + return (statusCodeEnum != null) ? statusCodeEnum.toString() : null; + } +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java new file mode 100644 index 000000000..98eeed221 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited 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.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciResponseWrapper extends PciWrapper implements Serializable { + + private static final long serialVersionUID = 109837814781086802L; + + @SerializedName(value = "body") + private PciResponse body; + + public PciResponseWrapper() { + super(); + } + + /** + * Get the body. + * + * @return the body + */ + public PciResponse getBody() { + return body; + } + + /** + * Set the body. + * + * @param body + * the body to set + */ + public void setBody(PciResponse body) { + this.body = body; + } + + @Override + public String toString() { + return "ResponseWrapper [body=" + body + ", toString()=" + super.toString() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((body == null) ? 0 : body.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PciResponseWrapper other = (PciResponseWrapper) obj; + if (body == null) { + if (other.body != null) { + return false; + } + } else if (!body.equals(other.body)) { + return false; + } + return true; + } +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java new file mode 100644 index 000000000..7b8b5b1c1 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java @@ -0,0 +1,214 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited 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.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciWrapper implements Serializable { + + private static final long serialVersionUID = 375215806432396532L; + + @SerializedName(value = "version") + private String version; + + @SerializedName(value = "cambria-partition") + private String cambriaPartition; + + @SerializedName(value = "rpc-name") + private String rpcName; + + @SerializedName(value = "correlation-id") + private String correlationId; + + @SerializedName(value = "type") + private String type; + + public PciWrapper() { + // Create a default PciWrapper instance + } + + /** + * Get the version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Set the version. + * + * @param version + * the version to set + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Get the cambria partition. + * + * @return the cambriaPartition + */ + public String getCambriaPartition() { + return cambriaPartition; + } + + /** + * Set the cambria partition. + * + * @param cambriaPartition + * the cambriaPartition to set + */ + public void setCambriaPartition(String cambriaPartition) { + this.cambriaPartition = cambriaPartition; + } + + /** + * Get the RPN name. + * + * @return the rpcName + */ + public String getRpcName() { + return rpcName; + } + + /** + * Set the RPC name. + * + * @param rpcName + * the rpcName to set + */ + public void setRpcName(String rpcName) { + this.rpcName = rpcName; + } + + /** + * Get the correlation Id. + * + * @return the correlationId + */ + public String getCorrelationId() { + return correlationId; + } + + /** + * Set the correclation Id. + * + * @param correlationId + * the correlationId to set + */ + public void setCorrelationId(String correlationId) { + this.correlationId = correlationId; + } + + /** + * Get the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Set the type. + * + * @param type + * the type to set + */ + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "Wrapper [version=" + version + ", cambriaPartition=" + cambriaPartition + ", rpcName=" + rpcName + + ", correlationId=" + correlationId + ", type=" + type + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cambriaPartition == null) ? 0 : cambriaPartition.hashCode()); + result = prime * result + ((correlationId == null) ? 0 : correlationId.hashCode()); + result = prime * result + ((rpcName == null) ? 0 : rpcName.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((version == null) ? 0 : version.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; + } + PciWrapper other = (PciWrapper) obj; + if (cambriaPartition == null) { + if (other.cambriaPartition != null) { + return false; + } + } else if (!cambriaPartition.equals(other.cambriaPartition)) { + return false; + } + if (correlationId == null) { + if (other.correlationId != null) { + return false; + } + } else if (!correlationId.equals(other.correlationId)) { + return false; + } + if (rpcName == null) { + if (other.rpcName != null) { + return false; + } + } else if (!rpcName.equals(other.rpcName)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + if (version == null) { + if (other.version != null) { + return false; + } + } else if (!version.equals(other.version)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java new file mode 100644 index 000000000..b4fead1d3 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited 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.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class Status implements Serializable { + + private static final long serialVersionUID = 877641506135467199L; + + @SerializedName(value = "Code") + private int code; + + @SerializedName(value = "Value") + private String value; + + public Status() { + // Create a default PciResponseStatus instance + } + + /** + * Constructor for the class Status. + * + */ + public Status(int code, String value) { + super(); + this.code = code; + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + @Override + public String toString() { + return "Status [code = " + code + ", value = " + value + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + code; + result = prime * result + ((value == null) ? 0 : value.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; + } + Status other = (Status) obj; + if (code != other.code) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java new file mode 100644 index 000000000..2acb6e8b2 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018 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.sdnr.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.JsonObject; +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 org.onap.policy.sdnr.PciRequest; +import org.onap.policy.sdnr.PciResponse; + + +public final class Serialization { + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); + + public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(PciRequest.class, new RequestAdapter()) + .registerTypeAdapter(PciResponse.class, new ResponseAdapter()).create(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); + + private Serialization() {} + + public static class RequestAdapter implements JsonSerializer<PciRequest>, JsonDeserializer<PciRequest> { + + @Override + public JsonElement serialize(PciRequest src, Type typeOfSrc, JsonSerializationContext context) { + JsonElement requestJson = gsonPretty.toJsonTree(src, PciRequest.class); + JsonObject input = new JsonObject(); + input.add("input", requestJson); + + return input; + } + + @Override + public PciRequest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return gsonPretty.fromJson(json.getAsJsonObject().get("input"), PciRequest.class); + } + } + + public static class ResponseAdapter implements JsonSerializer<PciResponse>, JsonDeserializer<PciResponse> { + + @Override + public JsonElement serialize(PciResponse src, Type typeOfSrc, JsonSerializationContext context) { + JsonElement responseJson = gsonPretty.toJsonTree(src, PciResponse.class); + JsonObject output = new JsonObject(); + output.add("output", responseJson); + return output; + } + + @Override + public PciResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return gsonPretty.fromJson(json.getAsJsonObject().get("output"), PciResponse.class); + } + } + + public static class InstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.parse(json.getAsString()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + } + + public static class InstantJunitAdapter 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/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java new file mode 100644 index 000000000..483062d6f --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.sdnr.util; + +public enum StatusCodeEnum { + ACCEPTED("ACCEPTED"), ERROR("ERROR"), REJECT("REJECT"), SUCCESS("SUCCESS"), FAILURE("FAILURE"), + PARTIAL_SUCCESS("PARTIAL SUCCESS"), PARTIAL_FAILURE("PARTIAL FAILURE"); + + private String name; + + StatusCodeEnum(final String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } + + /** + * Determine status enum from the code. + * + * @param statusCode integer code indicating the status + * @return enum representation of status code + */ + public static StatusCodeEnum fromStatusCode(final int statusCode) { + if (statusCode == 100) { + return ACCEPTED; + } + + if (statusCode == 200) { + return SUCCESS; + } + + if (isRejectStatusCode(statusCode)) { + return REJECT; + } + + if (statusCode == 400) { + return ERROR; + } + + if (isFailureStatusCode(statusCode)) { + return FAILURE; + } + + if (statusCode == 500) { + return PARTIAL_SUCCESS; + } + + if (isPartialFailureStatusCode(statusCode)) { + return PARTIAL_FAILURE; + } + + return null; + } + + private static boolean isRejectStatusCode(final int statusCode) { + return statusCode >= 300 && statusCode <= 313; + } + + private static boolean isFailureStatusCode(final int statusCode) { + return statusCode == 450 || (statusCode >= 401 && statusCode <= 406); + } + + private static boolean isPartialFailureStatusCode(final int statusCode) { + return statusCode >= 501 && statusCode <= 599; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/resources/definitions.yaml b/models-interactions/model-impl/sdnr/src/main/resources/definitions.yaml new file mode 100644 index 000000000..245569be2 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/resources/definitions.yaml @@ -0,0 +1,119 @@ +### +# ============LICENSE_START======================================================= +# sdnr +# ================================================================================ +# Copyright (C) 2018 Wipro Limited 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========================================================= +### + +Request: + type: object + properties: + CommonHeader: + type: object + properties: + TimeStamp: + type: string + APIver: + type: string + value: '1.01' + OriginatorID: + type: string + RequestID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + SubRequestID: + type: string + Flags: + type: object + required: + - TimeStamp + - APIver + - OriginatorID + - RequestID + Action: + type: string + enum: + - Audit + - ActionStatus + - BlockAudits + - Configure + - HealthCheck + - Install + - LiveUpgrade + - Migrate + - ModifyConfig + - Query + - Rebuild + - Reconfigure + - Restart + - Rollback + - Scale + - Start + - Stop + - Sync + - Terminate + - Test + - Upgrade + TargetID: + type: string + ObjectID: + type: string + Payload: + type: object + required: + - CommonHeader + - Action + - TargetID +Response: + type: object + properties: + CommonHeader: + type: object + properties: + TimeStamp: + type: string + APIver: + type: string + OriginatorID: + type: string + RequestID: + type: string + SubRequestID: + type: string + Flags: + type: object + required: + - TimeStamp + - APIver + - OriginatorID + - RequestID + Status: + type: object + properties: + Code: + type: integer + Value: + type: string + required: + - Code + - Value + Payload: + type: object + required: + - CommonHeader + - Status + |