aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-requests-db
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-requests-db')
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/CloudApiRequests.java138
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java3
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java33
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java26
-rw-r--r--mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/requestsdb/RequestsDBHelperTest.java81
5 files changed, 276 insertions, 5 deletions
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/CloudApiRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/CloudApiRequests.java
new file mode 100644
index 0000000000..690d0ffbaf
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/CloudApiRequests.java
@@ -0,0 +1,138 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017-2019 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.so.db.request.beans;
+
+import java.io.Serializable;
+import java.util.Date;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.PrePersist;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.openpojo.business.annotation.BusinessKey;
+
+
+@Entity
+@JsonInclude(Include.NON_NULL)
+@Table(name = "cloud_api_requests")
+public class CloudApiRequests implements Serializable {
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4686890103198488984L;
+
+ @JsonIgnore
+ @Id
+ @BusinessKey
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "ID")
+ private Integer id;
+
+
+ @Column(name = "SO_REQUEST_ID")
+ private String requestId;
+
+ public String getRequestId() {
+ return requestId;
+ }
+
+ public void setRequestId(String requestId) {
+ this.requestId = requestId;
+ }
+
+ @Column(name = "CLOUD_IDENTIFIER")
+ private String cloudIdentifier;
+
+ @Column(name = "REQUEST_BODY", columnDefinition = "LONGTEXT")
+ private String requestBody;
+
+ @Column(name = "CREATE_TIME", insertable = false, updatable = false)
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date created = null;
+
+
+ @Override
+ public boolean equals(final Object other) {
+ if (!(other instanceof CloudApiRequests)) {
+ return false;
+ }
+ CloudApiRequests castOther = (CloudApiRequests) other;
+ return new EqualsBuilder().append(id, castOther.id).isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(id).toHashCode();
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("id", id).append("cloudIdentifier", cloudIdentifier)
+ .append("requestBody", requestBody).append("created", created).toString();
+ }
+
+ @PrePersist
+ protected void createdAt() {
+ this.created = new Date();
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getCloudIdentifier() {
+ return cloudIdentifier;
+ }
+
+ public void setCloudIdentifier(String cloudIdentifier) {
+ this.cloudIdentifier = cloudIdentifier;
+ }
+
+
+ public String getRequestBody() {
+ return requestBody;
+ }
+
+ public void setRequestBody(String requestBody) {
+ this.requestBody = requestBody;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java
index 37fbfd023c..9aa04ea8b2 100644
--- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java
@@ -87,6 +87,7 @@ public class InfraActiveRequests extends InfraRequests {
.append("networkName", getNetworkName()).append("networkType", getNetworkType())
.append("requestorId", getRequestorId()).append("configurationId", getConfigurationId())
.append("configurationName", getConfigurationName()).append("operationalEnvId", getOperationalEnvId())
- .append("operationalEnvName", getOperationalEnvName()).append("requestUrl", getRequestUrl()).toString();
+ .append("operationalEnvName", getOperationalEnvName()).append("requestUrl", getRequestUrl())
+ .append("originalRequestId", getOriginalRequestId()).toString();
}
}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java
index a1010a349c..5b40e40eb9 100644
--- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java
@@ -22,11 +22,17 @@ package org.onap.so.db.request.beans;
import java.net.URI;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import java.util.Objects;
+import javax.persistence.CascadeType;
import javax.persistence.Column;
+import javax.persistence.FetchType;
import javax.persistence.Id;
+import javax.persistence.JoinColumn;
import javax.persistence.MappedSuperclass;
+import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
@@ -34,6 +40,7 @@ import javax.persistence.TemporalType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.onap.so.requestsdb.TimestampXMLAdapter;
+import uk.co.blackpepper.bowman.annotation.LinkedResource;
import uk.co.blackpepper.bowman.annotation.ResourceId;
@MappedSuperclass
@@ -146,6 +153,12 @@ public abstract class InfraRequests implements java.io.Serializable {
private String instanceGroupName;
@Column(name = "REQUEST_URL", length = 500)
private String requestUrl;
+ @Column(name = "ORIGINAL_REQUEST_ID", length = 45)
+ private String originalRequestId;
+
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @JoinColumn(name = "SO_REQUEST_ID", referencedColumnName = "REQUEST_ID")
+ private List<CloudApiRequests> cloudApiRequests = new ArrayList<>();
@ResourceId
public URI getRequestURI() {
@@ -458,6 +471,15 @@ public abstract class InfraRequests implements java.io.Serializable {
return requestAction;
}
+ @LinkedResource
+ public List<CloudApiRequests> getCloudApiRequests() {
+ return cloudApiRequests;
+ }
+
+ public void setCloudApiRequests(List<CloudApiRequests> cloudApiRequests) {
+ this.cloudApiRequests = cloudApiRequests;
+ }
+
public void setRequestAction(String requestAction) {
this.requestAction = requestAction;
}
@@ -550,6 +572,14 @@ public abstract class InfraRequests implements java.io.Serializable {
this.requestUrl = requestUrl;
}
+ public String getOriginalRequestId() {
+ return this.originalRequestId;
+ }
+
+ public void setOriginalRequestId(String originalRequestId) {
+ this.originalRequestId = originalRequestId;
+ }
+
@PrePersist
protected void onCreate() {
if (requestScope == null)
@@ -611,6 +641,7 @@ public abstract class InfraRequests implements java.io.Serializable {
.append("requestorId", getRequestorId()).append("configurationId", getConfigurationId())
.append("configurationName", getConfigurationName()).append("operationalEnvId", getOperationalEnvId())
.append("operationalEnvName", getOperationalEnvName()).append("instanceGroupId", getInstanceGroupId())
- .append("instanceGroupName", getInstanceGroupName()).append("requestUrl", getRequestUrl()).toString();
+ .append("instanceGroupName", getInstanceGroupName()).append("requestUrl", getRequestUrl())
+ .append("originalRequestId", originalRequestId).toString();
}
}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
index f2ff6fac00..1867b85de6 100644
--- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
@@ -67,15 +67,17 @@ public class RequestsDbClient {
private static final String SERVICE_ID = "SERVICE_ID";
private static final String OPERATION_ID = "OPERATION_ID";
private static final String SO_REQUEST_ID = "SO_REQUEST_ID";
+ private static final String NAME = "NAME";
+ private static final String GROUPING_ID = "GROUPING_ID";
private static final String REQUEST_ID = "REQUEST_ID";
private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENV_ID";
private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID";
- @Value("${mso.adapters.requestDb.endpoint}")
+ @Value("${mso.adapters.requestDb.endpoint:#{null}}")
protected String endpoint;
- @Value("${mso.adapters.requestDb.auth}")
+ @Value("${mso.adapters.requestDb.auth:#{null}}")
private String msoAdaptersAuth;
private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/";
@@ -104,7 +106,10 @@ public class RequestsDbClient {
private String requestProcessingDataURI = "/requestProcessingData";
- private final String findBySoRequestIdOrderByGroupingIdDesc =
+ private static final String findBySoRequestIdAndGroupIdAndName =
+ "/requestProcessingData/search/findOneBySoRequestIdAndGroupingIdAndName";
+
+ private static final String findBySoRequestIdOrderByGroupingIdDesc =
"/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc";
@@ -333,12 +338,27 @@ public class RequestsDbClient {
restTemplate.postForLocation(uri, entity);
}
+ public void updateRequestProcessingData(RequestProcessingData requestProcessingData) {
+ HttpHeaders headers = getHttpHeaders();
+ URI uri = getUri(requestProcessingDataURI);
+ HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers);
+ restTemplate.put(uri, entity);
+ }
+
public List<RequestProcessingData> getRequestProcessingDataBySoRequestId(String soRequestId) {
return this
.getRequestProcessingData(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdOrderByGroupingIdDesc)
.queryParam(SO_REQUEST_ID, soRequestId).build().toString()));
}
+ public RequestProcessingData getRequestProcessingDataBySoRequestIdAndNameAndGrouping(String soRequestId,
+ String name, String groupingId) {
+ return getClientFactory().create(RequestProcessingData.class)
+ .get(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdAndGroupIdAndName)
+ .queryParam(SO_REQUEST_ID, soRequestId).queryParam(NAME, name)
+ .queryParam(GROUPING_ID, groupingId).build().toString()));
+ }
+
private List<RequestProcessingData> getRequestProcessingData(URI uri) {
Iterable<RequestProcessingData> requestProcessingDataIterator =
getClientFactory().create(RequestProcessingData.class).getAll(uri);
diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/requestsdb/RequestsDBHelperTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/requestsdb/RequestsDBHelperTest.java
new file mode 100644
index 0000000000..b37ca0af63
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/requestsdb/RequestsDBHelperTest.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Samsung 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.so.requestsdb;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.client.RequestsDbClient;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RequestsDBHelperTest {
+
+ @InjectMocks
+ private RequestsDBHelper requestsDBHelper;
+
+ @Mock
+ private RequestsDbClient requestsDbClient;
+
+ @Test
+ public void updateInfraSuccessCompletion() {
+
+ when(requestsDbClient.getInfraActiveRequestbyRequestId(any())).thenReturn(new InfraActiveRequests());
+
+ requestsDBHelper.updateInfraSuccessCompletion("messageText", "requestId", "operationalEnvId");
+
+ ArgumentCaptor<InfraActiveRequests> infraActiveRequests = ArgumentCaptor.forClass(InfraActiveRequests.class);
+
+ verify(requestsDbClient, times(1)).save(infraActiveRequests.capture());
+ assertEquals("COMPLETE", infraActiveRequests.getValue().getRequestStatus());
+ assertEquals("APIH", infraActiveRequests.getValue().getLastModifiedBy());
+ assertEquals(Long.valueOf(100), infraActiveRequests.getValue().getProgress());
+ assertEquals("SUCCESSFUL, operationalEnvironmentId - operationalEnvId; Success Message: messageText",
+ infraActiveRequests.getValue().getStatusMessage());
+ assertEquals("operationalEnvId", infraActiveRequests.getValue().getOperationalEnvId());
+ }
+
+ @Test
+ public void updateInfraFailureCompletion() {
+
+ when(requestsDbClient.getInfraActiveRequestbyRequestId(any())).thenReturn(new InfraActiveRequests());
+
+ requestsDBHelper.updateInfraFailureCompletion("messageText", "requestId", "operationalEnvId");
+
+ ArgumentCaptor<InfraActiveRequests> infraActiveRequests = ArgumentCaptor.forClass(InfraActiveRequests.class);
+ verify(requestsDbClient, times(1)).save(infraActiveRequests.capture());
+ assertEquals("FAILED", infraActiveRequests.getValue().getRequestStatus());
+ assertEquals("APIH", infraActiveRequests.getValue().getLastModifiedBy());
+ assertEquals(Long.valueOf(100), infraActiveRequests.getValue().getProgress());
+ assertEquals("FAILURE, operationalEnvironmentId - operationalEnvId; Error message: messageText",
+ infraActiveRequests.getValue().getStatusMessage());
+ assertEquals("operationalEnvId", infraActiveRequests.getValue().getOperationalEnvId());
+
+ }
+}