diff options
Diffstat (limited to 'appc')
9 files changed, 780 insertions, 0 deletions
diff --git a/appc/pom.xml b/appc/pom.xml new file mode 100644 index 000000000..893706c1d --- /dev/null +++ b/appc/pom.xml @@ -0,0 +1,46 @@ +<!-- + ============LICENSE_START======================================================= + Drools PDP Application Models + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.openecomp.policy.drools-applications</groupId> + <artifactId>appc</artifactId> + + <parent> + <groupId>org.openecomp.policy.drools-applications</groupId> + <artifactId>drools-pdp-apps</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.5</version> + <scope>provided</scope> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/appc/src/main/java/org/openecomp/policy/appc/CommonHeader.java b/appc/src/main/java/org/openecomp/policy/appc/CommonHeader.java new file mode 100644 index 000000000..dd743099c --- /dev/null +++ b/appc/src/main/java/org/openecomp/policy/appc/CommonHeader.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.appc; + +import java.io.Serializable; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.UUID; + +public class CommonHeader implements Serializable { + + private static final long serialVersionUID = -3581658269910980336L; + + public Instant TimeStamp = Instant.now(); + public String APIver = "1.01"; + public String OriginatorID; + public UUID RequestID; + public String SubRequestID; + public Collection<String> RequestTrack = new ArrayList<String>(); + public Collection<Map<String, String>> Flags = new ArrayList<Map<String, String>>(); + + public CommonHeader() { + + } + + public CommonHeader(CommonHeader commonHeader) { + this.OriginatorID = commonHeader.OriginatorID; + this.RequestID = commonHeader.RequestID; + this.SubRequestID = commonHeader.SubRequestID; + if (commonHeader.RequestTrack != null) { + this.RequestTrack.addAll(commonHeader.RequestTrack); + } + if (commonHeader.Flags != null) { + this.Flags.addAll(commonHeader.Flags); + } + } + + @Override + public String toString() { + return "CommonHeader [TimeStamp=" + TimeStamp + ", APIver=" + APIver + ", OriginatorID=" + OriginatorID + + ", 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 + ((OriginatorID == null) ? 0 : OriginatorID.hashCode()); + result = prime * result + ((RequestID == null) ? 0 : RequestID.hashCode()); + result = prime * result + ((RequestTrack == null) ? 0 : RequestTrack.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; + CommonHeader other = (CommonHeader) 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 (OriginatorID == null) { + if (other.OriginatorID != null) + return false; + } else if (!OriginatorID.equals(other.OriginatorID)) + return false; + if (RequestID == null) { + if (other.RequestID != null) + return false; + } else if (!RequestID.equals(other.RequestID)) + return false; + if (RequestTrack == null) { + if (other.RequestTrack != null) + return false; + } else if (!RequestTrack.equals(other.RequestTrack)) + 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/appc/src/main/java/org/openecomp/policy/appc/Request.java b/appc/src/main/java/org/openecomp/policy/appc/Request.java new file mode 100644 index 000000000..933692378 --- /dev/null +++ b/appc/src/main/java/org/openecomp/policy/appc/Request.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.appc; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +public class Request implements Serializable{ + + private static final long serialVersionUID = -3912323643990646431L; + + public CommonHeader CommonHeader; + public String Action; + public String TargetID; + public String ObjectID; + public Map<String, Object> Payload = new HashMap<String, Object>(); + + public Request() { + + } + + public CommonHeader getCommonHeader() { + return CommonHeader; + } + + public Map<String, Object> getPayload() { + return Payload; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((Action == null) ? 0 : Action.hashCode()); + result = prime * result + ((CommonHeader == null) ? 0 : CommonHeader.hashCode()); + result = prime * result + ((ObjectID == null) ? 0 : ObjectID.hashCode()); + result = prime * result + ((Payload == null) ? 0 : Payload.hashCode()); + result = prime * result + ((TargetID == null) ? 0 : TargetID.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; + Request other = (Request) obj; + if (Action == null) { + if (other.Action != null) + return false; + } else if (!Action.equals(other.Action)) + return false; + if (CommonHeader == null) { + if (other.CommonHeader != null) + return false; + } else if (!CommonHeader.equals(other.CommonHeader)) + return false; + if (ObjectID == null) { + if (other.ObjectID != null) + return false; + } else if (!ObjectID.equals(other.ObjectID)) + return false; + if (Payload == null) { + if (other.Payload != null) + return false; + } else if (!Payload.equals(other.Payload)) + return false; + if (TargetID == null) { + if (other.TargetID != null) + return false; + } else if (!TargetID.equals(other.TargetID)) + return false; + return true; + } + + @Override + public String toString() { + return "Request [CommonHeader=" + CommonHeader + ", Action=" + Action + ", TargetID=" + TargetID + ", ObjectID=" + + ObjectID + ", Payload=" + Payload + "]"; + } + +} diff --git a/appc/src/main/java/org/openecomp/policy/appc/Response.java b/appc/src/main/java/org/openecomp/policy/appc/Response.java new file mode 100644 index 000000000..a093f35a1 --- /dev/null +++ b/appc/src/main/java/org/openecomp/policy/appc/Response.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.appc; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +public class Response implements Serializable { + + private static final long serialVersionUID = 434953706339865151L; + + public CommonHeader CommonHeader; + public ResponseStatus Status = new ResponseStatus(); + public Map<String, Object> Payload = new HashMap<String, Object>(); + + public Response() { + + } + + public Response(Request request) { + this.CommonHeader = new CommonHeader(request.CommonHeader); + if (request.Payload != null) { + this.Payload.putAll(request.Payload); + } + } + + public CommonHeader getCommonHeader() { + return CommonHeader; + } + + public void setCommonHeader(CommonHeader commonHeader) { + CommonHeader = commonHeader; + } + + public ResponseStatus getStatus() { + return Status; + } + + public void setStatus(ResponseStatus status) { + Status = status; + } + + public Map<String, Object> getPayload() { + return Payload; + } + + public void setPayload(Map<String, Object> payload) { + Payload = payload; + } + + @Override + public String toString() { + return "Response [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; + Response other = (Response) 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/appc/src/main/java/org/openecomp/policy/appc/ResponseCode.java b/appc/src/main/java/org/openecomp/policy/appc/ResponseCode.java new file mode 100644 index 000000000..11c5539b1 --- /dev/null +++ b/appc/src/main/java/org/openecomp/policy/appc/ResponseCode.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.appc; + +public enum ResponseCode { + ACCEPT(100), + ERROR(200), + REJECT(300), + SUCCESS(400), + FAILURE(500) + ; + + private Integer code; + + private ResponseCode(int code) { + this.code = code; + } + + public int getValue() { + return this.code; + } + + public String toString() { + return Integer.toString(this.code); + } + + public static ResponseCode toResponseCode(int code) { + if (code == ACCEPT.code) { + return ACCEPT; + } + if (code == ERROR.code) { + return ERROR; + } + if (code == REJECT.code) { + return REJECT; + } + if (code == SUCCESS.code) { + return SUCCESS; + } + if (code == FAILURE.code) { + return FAILURE; + } + return null; + } +} diff --git a/appc/src/main/java/org/openecomp/policy/appc/ResponseStatus.java b/appc/src/main/java/org/openecomp/policy/appc/ResponseStatus.java new file mode 100644 index 000000000..f8adb21da --- /dev/null +++ b/appc/src/main/java/org/openecomp/policy/appc/ResponseStatus.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.appc; + +import java.io.Serializable; + +public class ResponseStatus implements Serializable { + + private static final long serialVersionUID = 2421770469587860452L; + + public int Code; + public String Value; + public String Description; + + @Override + public String toString() { + return "ResponseStatus [Code=" + Code + ", Value=" + Value + ", Description=" + Description + "]"; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Code; + result = prime * result + ((Description == null) ? 0 : Description.hashCode()); + 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; + ResponseStatus other = (ResponseStatus) obj; + if (Code != other.Code) + return false; + if (Description == null) { + if (other.Description != null) + return false; + } else if (!Description.equals(other.Description)) + return false; + if (Value == null) { + if (other.Value != null) + return false; + } else if (!Value.equals(other.Value)) + return false; + return true; + } + +} diff --git a/appc/src/main/java/org/openecomp/policy/appc/ResponseValue.java b/appc/src/main/java/org/openecomp/policy/appc/ResponseValue.java new file mode 100644 index 000000000..18a1c2953 --- /dev/null +++ b/appc/src/main/java/org/openecomp/policy/appc/ResponseValue.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.appc; + +public enum ResponseValue { + ACCEPT("ACCEPT"), + ERROR("ERROR"), + REJECT("REJECT"), + SUCCESS("SUCCESS"), + FAILURE("FAILURE") + ; + + private String value; + + private ResponseValue(String value) { + this.value = value; + } + + public String toString() { + return this.value; + } + + public static ResponseValue toResponseValue(String value) { + if (value.toString().equals(ACCEPT.toString())) { + return ACCEPT; + } + if (value.toString().equals(ERROR.toString())) { + return ERROR; + } + if (value.toString().equals(REJECT.toString())) { + return REJECT; + } + if (value.toString().equals(SUCCESS.toString())) { + return SUCCESS; + } + if (value.toString().equals(FAILURE.toString())) { + return FAILURE; + } + + return null; + } + +} diff --git a/appc/src/main/java/org/openecomp/policy/appc/util/Serialization.java b/appc/src/main/java/org/openecomp/policy/appc/util/Serialization.java new file mode 100644 index 000000000..b1b3ad8aa --- /dev/null +++ b/appc/src/main/java/org/openecomp/policy/appc/util/Serialization.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.appc.util; + +import java.lang.reflect.Type; +import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +public final class Serialization { + + public static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + + public static class gsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { + + public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) + throws JsonParseException { + try { + return ZonedDateTime.parse(element.getAsString(), format); + } catch (Exception e) { + System.err.println(e); + } + return null; + } + + public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) { + return new JsonPrimitive(datetime.format(format)); + } + } + public static class gsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + + public static final Gson gsonPretty = new GsonBuilder() + .disableHtmlEscaping() + .setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new gsonUTCAdapter()) + .registerTypeAdapter(Instant.class, new gsonInstantAdapter()) +// .registerTypeAdapter(CommonHeader1607.class, new gsonCommonHeaderInstance()) +// .registerTypeAdapter(ResponseStatus1607.class, new gsonResponseStatus()) + .create(); + +} diff --git a/appc/src/main/resources/definitions.yaml b/appc/src/main/resources/definitions.yaml new file mode 100644 index 000000000..680a9929c --- /dev/null +++ b/appc/src/main/resources/definitions.yaml @@ -0,0 +1,118 @@ +### +# ============LICENSE_START======================================================= +# appc +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +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 + |