From 38f720752af4d4aad8c4e467a288d9048659f688 Mon Sep 17 00:00:00 2001 From: Rob Daugherty Date: Wed, 14 Mar 2018 02:07:32 -0400 Subject: AT&T 1712 and 1802 release code This is code from AT&T's 1712 and 1802 releases. Change-Id: Ie1e85851e94bc66c4d9514a0226c221939531a04 Issue-ID: SO-425 Signed-off-by: Rob Daugherty --- .../org/openecomp/mso/client/ruby/RubyClient.java | 90 +++++++++ .../org/openecomp/mso/client/ruby/beans/Event.java | 67 +++++++ .../mso/client/ruby/beans/MsoRequest.java | 207 +++++++++++++++++++++ .../org/openecomp/mso/client/ruby/beans/Ruby.java | 68 +++++++ .../dmaap/RubyCreateTicketRequestPublisher.java | 56 ++++++ 5 files changed, 488 insertions(+) create mode 100644 common/src/main/java/org/openecomp/mso/client/ruby/RubyClient.java create mode 100644 common/src/main/java/org/openecomp/mso/client/ruby/beans/Event.java create mode 100644 common/src/main/java/org/openecomp/mso/client/ruby/beans/MsoRequest.java create mode 100644 common/src/main/java/org/openecomp/mso/client/ruby/beans/Ruby.java create mode 100644 common/src/main/java/org/openecomp/mso/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java (limited to 'common/src/main/java/org/openecomp/mso/client/ruby') diff --git a/common/src/main/java/org/openecomp/mso/client/ruby/RubyClient.java b/common/src/main/java/org/openecomp/mso/client/ruby/RubyClient.java new file mode 100644 index 0000000000..a4adcb23f7 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/ruby/RubyClient.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.mso.client.ruby; + +import java.io.IOException; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import org.openecomp.mso.client.dmaap.DmaapPublisher; +import org.openecomp.mso.client.ruby.beans.Event; +import org.openecomp.mso.client.ruby.beans.MsoRequest; +import org.openecomp.mso.client.ruby.beans.Ruby; +import org.openecomp.mso.client.ruby.dmaap.RubyCreateTicketRequestPublisher; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + + +public class RubyClient { + + private static final String REQUEST_CLIENT_NAME = "MSO"; + private static final String ACTION = "Create Ticket"; + + protected String buildRequest(String requestId, String sourceName, String reason, String workflowId, String notification) throws JsonProcessingException { + final MsoRequest request = new MsoRequest(); + request.withRequestClientName(REQUEST_CLIENT_NAME) + .withRequestId(requestId) + .withSourceName(sourceName) + .withWorkflowId(workflowId) + .withAction(ACTION); + + request.withRequestTime(this.getTime()); + + if(reason.length() <= 255){ + request.withReason(reason); + } else { + throw new IllegalArgumentException("reason exceeds 255 characters"); + } + if(notification.length() <= 1024){ + request.withNotification(notification); + } else { + throw new IllegalArgumentException("notification exceeds 1024 characters"); + } + final Event event = new Event(); + event.setMsoRequest(request); + final Ruby ruby = new Ruby(); + ruby.setEvent(event); + return this.getJson(ruby); + } + + protected String getJson(Ruby obj) throws JsonProcessingException { + final ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(obj); + } + + protected DmaapPublisher getPublisher() throws IOException { + return new RubyCreateTicketRequestPublisher(); + } + + protected String getTime() { + final ZonedDateTime currentDateTime = ZonedDateTime.now(ZoneOffset.UTC); + final DateTimeFormatter format = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z"); + return currentDateTime.format(format); + } + + public void rubyCreateTicketCheckRequest(String requestId, String sourceName, String reason, String workflowId, String notification) throws Exception { + String request = this.buildRequest(requestId, sourceName, reason, workflowId, notification); + final DmaapPublisher publisher = this.getPublisher(); + publisher.send(request); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/ruby/beans/Event.java b/common/src/main/java/org/openecomp/mso/client/ruby/beans/Event.java new file mode 100644 index 0000000000..b9263596be --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/ruby/beans/Event.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.mso.client.ruby.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ +"msoRequest" +}) +public class Event { + +@JsonProperty("msoRequest") +private MsoRequest msoRequest; + +/** +* No args constructor for use in serialization +* +*/ +public Event() { + } + +/** +* +* @param msoRequest +*/ +public Event(MsoRequest msoRequest) { +super(); +this.msoRequest = msoRequest; + } + +@JsonProperty("msoRequest") +public MsoRequest getMsoRequest() { +return msoRequest; + } + +@JsonProperty("msoRequest") +public void setMsoRequest(MsoRequest msoRequest) { +this.msoRequest = msoRequest; + } + +public Event withMsoRequest(MsoRequest msoRequest) { +this.msoRequest = msoRequest; +return this; + } + +} \ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/ruby/beans/MsoRequest.java b/common/src/main/java/org/openecomp/mso/client/ruby/beans/MsoRequest.java new file mode 100644 index 0000000000..d00adae88a --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/ruby/beans/MsoRequest.java @@ -0,0 +1,207 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.mso.client.ruby.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ +"requestClientName", +"requestId", +"requestTime", +"sourceName", +"reason", +"action", +"workflowId", +"notification" +}) +public class MsoRequest { + +@JsonProperty("requestClientName") +private String requestClientName; +@JsonProperty("requestId") +private String requestId; +@JsonProperty("requestTime") +private String requestTime; +@JsonProperty("sourceName") +private String sourceName; +@JsonProperty("reason") +private String reason; +@JsonProperty("action") +private String action; +@JsonProperty("workflowId") +private String workflowId; +@JsonProperty("notification") +private String notification; + +/** +* No args constructor for use in serialization +* +*/ +public MsoRequest() { + } + +/** +* +* @param requestClientName +* @param requestTime +* @param reason +* @param requestId +* @param workflowId +* @param sourceName +* @param action +* @param notification +*/ +public MsoRequest(String requestClientName, String requestId, String requestTime, String sourceName, String reason, String action, String workflowId, String notification) { +super(); +this.requestClientName = requestClientName; +this.requestId = requestId; +this.requestTime = requestTime; +this.sourceName = sourceName; +this.reason = reason; +this.action = action; +this.workflowId = workflowId; +this.notification = notification; + } + +@JsonProperty("requestClientName") +public String getRequestClientName() { +return requestClientName; + } + +@JsonProperty("requestClientName") +public void setRequestClientName(String requestClientName) { +this.requestClientName = requestClientName; + } + +public MsoRequest withRequestClientName(String requestClientName) { +this.requestClientName = requestClientName; +return this; + } + +@JsonProperty("requestId") +public String getRequestId() { +return requestId; + } + +@JsonProperty("requestId") +public void setRequestId(String requestId) { +this.requestId = requestId; + } + +public MsoRequest withRequestId(String requestId) { +this.requestId = requestId; +return this; + } + +@JsonProperty("requestTime") +public String getRequestTime() { +return requestTime; + } + +@JsonProperty("requestTime") +public void setRequestTime(String requestTime) { +this.requestTime = requestTime; + } + +public MsoRequest withRequestTime(String requestTime) { +this.requestTime = requestTime; +return this; + } + +@JsonProperty("sourceName") +public String getSourceName() { +return sourceName; + } + +@JsonProperty("sourceName") +public void setSourceName(String sourceName) { +this.sourceName = sourceName; + } + +public MsoRequest withSourceName(String sourceName) { +this.sourceName = sourceName; +return this; + } + +@JsonProperty("reason") +public String getReason() { +return reason; + } + +@JsonProperty("reason") +public void setReason(String reason) { +this.reason = reason; + } + +public MsoRequest withReason(String reason) { +this.reason = reason; +return this; + } + +@JsonProperty("action") +public String getAction() { +return action; + } + +@JsonProperty("action") +public void setAction(String action) { +this.action = action; + } + +public MsoRequest withAction(String action) { +this.action = action; +return this; + } + +@JsonProperty("workflowId") +public String getWorkflowId() { +return workflowId; + } + +@JsonProperty("workflowId") +public void setWorkflowId(String workflowId) { +this.workflowId = workflowId; + } + +public MsoRequest withWorkflowId(String workflowId) { +this.workflowId = workflowId; +return this; + } + +@JsonProperty("notification") +public String getNotification() { +return notification; + } + +@JsonProperty("notification") +public void setNotification(String notification) { +this.notification = notification; + } + +public MsoRequest withNotification(String notification) { +this.notification = notification; +return this; + } + +} \ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/ruby/beans/Ruby.java b/common/src/main/java/org/openecomp/mso/client/ruby/beans/Ruby.java new file mode 100644 index 0000000000..1b81043faf --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/ruby/beans/Ruby.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.mso.client.ruby.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ +"event" +}) +public class Ruby { + +@JsonProperty("event") +private Event event; + +/** +* No args constructor for use in serialization +* +*/ +public Ruby() { + } + +/** +* +* @param event +*/ +public Ruby(Event event) { +super(); +this.event = event; + } + +@JsonProperty("event") +public Event getEvent() { +return event; + } + +@JsonProperty("event") +public void setEvent(Event event) { +this.event = event; + } + +public Ruby withEvent(Event event) { +this.event = event; +return this; + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java b/common/src/main/java/org/openecomp/mso/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java new file mode 100644 index 0000000000..521318f822 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.mso.client.ruby.dmaap; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Optional; + +import org.openecomp.mso.client.dmaap.DmaapPublisher; + +public class RubyCreateTicketRequestPublisher extends DmaapPublisher{ + public RubyCreateTicketRequestPublisher() throws FileNotFoundException, IOException { + super(); + } + + @Override + public String getUserName() { + return msoProperties.get("ruby.create-ticket-request.dmaap.username"); + } + + @Override + public String getPassword() { + return msoProperties.get("ruby.create-ticket-request.dmaap.password"); + } + + @Override + public String getTopic() { + return msoProperties.get("ruby.create-ticket-request.publisher.topic"); + } + + @Override + public Optional getHost() { + return Optional.ofNullable(msoProperties.get("ruby.create-ticket-request.publisher.host")); + } + +} + + -- cgit 1.2.3-korg