diff options
26 files changed, 262 insertions, 143 deletions
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTest.java new file mode 100644 index 0000000000..87e2a87138 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.adapters.requestsdb; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openecomp.mso.HealthCheckUtils; +import org.openecomp.mso.logger.MsoLogger; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import javax.ws.rs.core.Response; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(HealthCheckHandler.class) +public class HealthCheckHandlerTest { + + HealthCheckHandler hcH; + + @Before + public void init(){ + + hcH = new HealthCheckHandler(); + } + + @Test + public void testNoServiceResp() { + + HealthCheckUtils test = PowerMockito.mock(HealthCheckUtils.class); + try { + PowerMockito.whenNew(HealthCheckUtils.class).withNoArguments().thenReturn(test); + when(test.siteStatusCheck(any(MsoLogger.class))).thenReturn(true); + + } catch (Exception e) { + e.printStackTrace(); + } + Response response = hcH.healthcheck("request"); + assertEquals(503,response.getStatus()); + } + +} + + diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTestException.java b/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTestException.java deleted file mode 100644 index 994ce5dbb3..0000000000 --- a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTestException.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.adapters.requestsdb; - -import org.junit.Test; - -public class HealthCheckHandlerTestException { - - @Test(expected = NullPointerException.class) - public void testHealthCheckSiteNameNull() { - - HealthCheckHandler hcH = new HealthCheckHandler(); - hcH.healthcheck("request"); - } -} - - diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImplTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImplTest.java index 6e05402736..98b368f5fa 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImplTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImplTest.java @@ -20,43 +20,60 @@ package org.openecomp.mso.adapters.sdnc.impl; -import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.openecomp.mso.HealthCheckUtils; +import org.openecomp.mso.logger.MsoLogger; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import javax.ws.rs.core.Response; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(SDNCAdapterRestImpl.class) public class SDNCAdapterRestImplTest { - SDNCAdapterRestImpl test = new SDNCAdapterRestImpl(); + SDNCAdapterRestImpl test; - /*Need to revist this .. commenting for now to proceed - @Test(expected = ClassFormatError.class) - public void testMSORequestException() { + @Before + public void init(){ - test.MSORequest("reqXML"); - Assert.assertFalse(true); - + test = new SDNCAdapterRestImpl(); } - @Test(expected = NoClassDefFoundError.class) - public void testHealthCheckException() { + @Test + public void testBadReqNoServiceRsp() { - test.healthcheck("1a25a7c0-4c91-4f74-9a78-8c11b7a57f1a"); - Assert.assertFalse(true); - } + HealthCheckUtils hCU = PowerMockito.mock(HealthCheckUtils.class); + try { + PowerMockito.whenNew(HealthCheckUtils.class).withNoArguments().thenReturn(hCU); + when(hCU.siteStatusCheck(any(MsoLogger.class))).thenReturn(true); - @Test(expected = ClassFormatError.class) - public void testglobalHealthcheckException() { + } catch (Exception e) { + e.printStackTrace(); + } - test.globalHealthcheck(true); - Assert.assertFalse(true); - } + String reqXML = "<xml>test</xml>"; + + Response response = test.MSORequest(reqXML); + assertEquals(400,response.getStatus()); + + response = test.healthcheck("1a25a7c0-4c91-4f74-9a78-8c11b7a57f1a"); + assertEquals(503,response.getStatus()); + response = test.globalHealthcheck(true); + assertEquals(503,response.getStatus()); - @Test(expected = NoClassDefFoundError.class) - public void testNodeHealthCheckException() { + response = test.nodeHealthcheck(); + assertEquals(503,response.getStatus()); - test.nodeHealthcheck(); - Assert.assertFalse(true); - }*/ + } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/notify/SDNCNotifyResourceTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/notify/SDNCNotifyResourceTest.java index a62f42af5a..75cd360663 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/notify/SDNCNotifyResourceTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/notify/SDNCNotifyResourceTest.java @@ -24,6 +24,9 @@ import org.junit.Test; import org.mockito.Mock; import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.Response; + +import static org.junit.Assert.assertEquals; public class SDNCNotifyResourceTest { @@ -31,16 +34,19 @@ public class SDNCNotifyResourceTest { HttpServletRequest httpServletRequest; SDNCNotifyResource test = new SDNCNotifyResource(); -//These tests need a recheck for the class cast exception - /* @Test(expected = ClassFormatError.class) - public void testPrintMessageException() { - test.printMessage(); - test.printMessageParam("msg"); - } - @Test(expected = ClassFormatError.class) - public void testSDNCNotifyException() { - test.SDNCNotify("reqXML", httpServletRequest); + @Test + public void testPrintMessage() { + + Response response = test.printMessage(); + assertEquals(200, response.getStatus()); - }*/ + response = test.printMessageParam("msg"); + assertEquals(200, response.getStatus()); + + String reqXML = "<xml>test</xml>"; + response = test.SDNCNotify(reqXML, httpServletRequest); + assertEquals(400, response.getStatus()); + + } } diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/tenantIsolation/AaiClientPropertiesImpl.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/tenantIsolation/AaiClientPropertiesImpl.java index 537de3e238..be5af5d51f 100644 --- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/tenantIsolation/AaiClientPropertiesImpl.java +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/tenantIsolation/AaiClientPropertiesImpl.java @@ -49,4 +49,14 @@ public class AaiClientPropertiesImpl implements AAIProperties { public AAIVersion getDefaultVersion() { return AAIVersion.LATEST; } + + @Override + public String getAuth() { + return props.getProperty("aai.auth", null); + } + + @Override + public String getKey() { + return props.getProperty("mso.msoKey", null); + } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/adapter/vnf/AdapterRestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/adapter/vnf/AdapterRestClient.java index 3e315a5f04..16fd351b43 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/adapter/vnf/AdapterRestClient.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/adapter/vnf/AdapterRestClient.java @@ -21,7 +21,6 @@ package org.openecomp.mso.client.adapter.vnf; import java.net.URI; -import java.security.GeneralSecurityException; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -29,8 +28,6 @@ import java.util.UUID; import javax.ws.rs.client.ClientResponseFilter; import javax.ws.rs.ext.ContextResolver; -import org.apache.commons.codec.binary.Base64; -import org.openecomp.mso.bpmn.common.util.CryptoUtils; import org.openecomp.mso.client.ResponseExceptionMapperImpl; import org.openecomp.mso.client.policy.JettisonStyleMapperProvider; import org.openecomp.mso.client.policy.RestClient; @@ -52,8 +49,7 @@ public class AdapterRestClient extends RestClient { @Override protected void initializeHeaderMap(Map<String, String> headerMap) { - headerMap.put("Authorization", - this.getBasicAuth(props.getAuth(), props.getKey())); + addBasicAuthHeader(props.getAuth(), props.getKey()); } @Override @@ -70,20 +66,4 @@ public class AdapterRestClient extends RestClient { protected ContextResolver<ObjectMapper> getMapper() { return new JettisonStyleMapperProvider(); } - - private String getBasicAuth(String encryptedAuth, String msoKey) { - if ((encryptedAuth == null || encryptedAuth.isEmpty()) || (msoKey == null || msoKey.isEmpty())) { - return null; - } - try { - String auth = CryptoUtils.decrypt(encryptedAuth, msoKey); - byte[] encoded = Base64.encodeBase64(auth.getBytes()); - String encodedString = new String(encoded); - encodedString = "Basic " + encodedString; - return encodedString; - } catch (GeneralSecurityException e) { - this.logger.warn(e.getMessage(), e); - return null; - } - } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/restproperties/AAIPropertiesImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/restproperties/AAIPropertiesImpl.java index 27352dc11d..a1ef35a49d 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/restproperties/AAIPropertiesImpl.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/restproperties/AAIPropertiesImpl.java @@ -52,4 +52,13 @@ public class AAIPropertiesImpl implements AAIProperties { return AAIVersion.LATEST; } + @Override + public String getAuth() { + return props.get("aai.auth"); + } + + @Override + public String getKey() { + return props.get("mso.msoKey"); + } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java index 5a8d741a05..edff36fe68 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java @@ -22,7 +22,7 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.DmaapClient; +import org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.DmaapClient; import org.springframework.beans.factory.annotation.Autowired; public class InformDmaapClient implements JavaDelegate { diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/DmaapClient.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/DmaapClient.java index 07e8ada21e..c6b6be6842 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/DmaapClient.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/DmaapClient.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.bpmn.infrastructure.pnf.implementation; +package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap; public interface DmaapClient { diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java index 6871665ba1..8c9903e87a 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java @@ -20,6 +20,7 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap; +import com.google.common.annotations.VisibleForTesting; import java.io.IOException; import java.net.URI; import java.util.Map; @@ -34,11 +35,10 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.DmaapClient; import org.openecomp.mso.jsonpath.JsonPathUtil; import org.openecomp.mso.logger.MsoLogger; -public class PnfEventReadyConsumer implements Runnable, DmaapClient { +public class PnfEventReadyConsumer implements DmaapClient { private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); @@ -54,9 +54,8 @@ public class PnfEventReadyConsumer implements Runnable, DmaapClient { private Map<String, Runnable> pnfCorrelationIdToThreadMap; private HttpGet getRequest; private ScheduledExecutorService executor; - private int dmaapClientInitialDelayInSeconds; private int dmaapClientDelayInSeconds; - private boolean dmaapThreadListenerIsRunning; + private volatile boolean dmaapThreadListenerIsRunning; public PnfEventReadyConsumer() { httpClient = HttpClientBuilder.create().build(); @@ -68,8 +67,9 @@ public class PnfEventReadyConsumer implements Runnable, DmaapClient { getRequest = new HttpGet(buildURI()); } - @Override - public void run() { + //TODO: extract this logic to separate class and test it there to avoid using VisibleForTesting + @VisibleForTesting + void sendRequest() { try { HttpResponse response = httpClient.execute(getRequest); getCorrelationIdFromResponse(response).ifPresent(this::informAboutPnfReadyIfCorrelationIdFound); @@ -79,21 +79,23 @@ public class PnfEventReadyConsumer implements Runnable, DmaapClient { } @Override - public void registerForUpdate(String correlationId, Runnable informConsumer) { + public synchronized void registerForUpdate(String correlationId, Runnable informConsumer) { pnfCorrelationIdToThreadMap.put(correlationId, informConsumer); if (!dmaapThreadListenerIsRunning) { startDmaapThreadListener(); } } - private void startDmaapThreadListener() { - executor = Executors.newScheduledThreadPool(1); - executor.scheduleWithFixedDelay(this, dmaapClientInitialDelayInSeconds, - dmaapClientDelayInSeconds, TimeUnit.SECONDS); - dmaapThreadListenerIsRunning = true; + private synchronized void startDmaapThreadListener() { + if (!dmaapThreadListenerIsRunning) { + executor = Executors.newScheduledThreadPool(1); + executor.scheduleWithFixedDelay(this::sendRequest, 0, + dmaapClientDelayInSeconds, TimeUnit.SECONDS); + dmaapThreadListenerIsRunning = true; + } } - private void stopDmaapThreadListener() { + private synchronized void stopDmaapThreadListener() { if (dmaapThreadListenerIsRunning) { executor.shutdownNow(); dmaapThreadListenerIsRunning = false; @@ -120,17 +122,14 @@ public class PnfEventReadyConsumer implements Runnable, DmaapClient { } - private void informAboutPnfReadyIfCorrelationIdFound(String correlationId) { - pnfCorrelationIdToThreadMap.keySet().stream().filter(key -> key.equals(correlationId)).findAny() - .ifPresent(this::informAboutPnfReady); - } - - private void informAboutPnfReady(String correlationId) { - pnfCorrelationIdToThreadMap.get(correlationId).run(); - pnfCorrelationIdToThreadMap.remove(correlationId); + private synchronized void informAboutPnfReadyIfCorrelationIdFound(String correlationId) { + Runnable runnable = pnfCorrelationIdToThreadMap.remove(correlationId); + if (runnable != null) { + runnable.run(); - if (pnfCorrelationIdToThreadMap.isEmpty()) { - stopDmaapThreadListener(); + if (pnfCorrelationIdToThreadMap.isEmpty()) { + stopDmaapThreadListener(); + } } } @@ -162,10 +161,6 @@ public class PnfEventReadyConsumer implements Runnable, DmaapClient { this.consumerGroup = consumerGroup; } - public void setDmaapClientInitialDelayInSeconds(int dmaapClientInitialDelayInSeconds) { - this.dmaapClientInitialDelayInSeconds = dmaapClientInitialDelayInSeconds; - } - public void setDmaapClientDelayInSeconds(int dmaapClientDelayInSeconds) { this.dmaapClientDelayInSeconds = dmaapClientDelayInSeconds; } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java index 3a8b6b9036..0aeb0c6310 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java @@ -255,7 +255,9 @@ public abstract class AbstractSdncOperationTask extends BaseTask { serviceId = StringUtils.isBlank(serviceId) ? (String) execution.getVariable("serviceInstanceId") : serviceId; String operationId = (String) execution.getVariable("operationId"); String resourceTemplateUUID = (String) execution.getVariable("resourceUUID"); - resourceTemplateUUID = StringUtils.isBlank(resourceTemplateUUID) ? (String) execution.getVariable("resourceTemplateId") : resourceTemplateUUID; + String resourceTemplateId = (String) execution.getVariable("resourceTemplateId"); + resourceTemplateId = StringUtils.isBlank(resourceTemplateId) ? "" : resourceTemplateUUID; + resourceTemplateUUID = StringUtils.isBlank(resourceTemplateUUID) ? resourceTemplateId : resourceTemplateUUID; try { ResourceOperationStatus resourceOperationStatus = getResourceOperationStatus(serviceId, operationId, resourceTemplateUUID); if (!StringUtils.isBlank(status)) { diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/client/builder/AbstractBuilder.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/client/builder/AbstractBuilder.java index de50fe11b5..09561a620e 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/client/builder/AbstractBuilder.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/client/builder/AbstractBuilder.java @@ -110,7 +110,7 @@ public abstract class AbstractBuilder<IN, OUT> { protected String getRequestActoin(DelegateExecution execution) { String action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.getName(); String operType = (String) execution.getVariable(OPERATION_TYPE); - String resourceType = ((String) execution.getVariable(RESOURCE_TYPE)).toLowerCase(); + String resourceType = (String)execution.getVariable(RESOURCE_TYPE); if (!StringUtils.isBlank(operType)) { if (RequestsDbConstant.OperationType.DELETE.equalsIgnoreCase(operType)) { if (isOverlay(resourceType)) { @@ -134,17 +134,17 @@ public abstract class AbstractBuilder<IN, OUT> { } private boolean isOverlay(String resourceType) { - return !StringUtils.isBlank(resourceType) && resourceType.contains("overlay"); + return !StringUtils.isBlank(resourceType) && resourceType.toLowerCase().contains("overlay"); } private boolean isUnderlay(String resourceType) { - return !StringUtils.isBlank(resourceType) && resourceType.contains("underlay"); + return !StringUtils.isBlank(resourceType) && resourceType.toLowerCase().contains("underlay"); } protected String getSvcAction(DelegateExecution execution) { String action = /*SdncRequestHeader.*/SvcAction.Create.getName(); String operType = (String) execution.getVariable(OPERATION_TYPE); - String resourceType = ((String) execution.getVariable(RESOURCE_TYPE)).toLowerCase(); + String resourceType = (String)execution.getVariable(RESOURCE_TYPE); if (!StringUtils.isBlank(operType)) { if (RequestsDbConstant.OperationType.DELETE.equalsIgnoreCase(operType)) { if (isOverlay(resourceType)) { diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml index cbb8266bf7..03fff4f974 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml +++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml @@ -27,7 +27,6 @@ <property name="dmaapTopicName" value="${eventReadyTopicName}"/>
<property name="consumerGroup" value="${consumerGroup}"/>
<property name="consumerId" value="${consumerId}"/>
- <property name="dmaapClientInitialDelayInSeconds" value="${clientThreadInitialDelayInSeconds}"/>
<property name="dmaapClientDelayInSeconds" value="${clientThreadDelayInSeconds}"/>
</bean>
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java index 1103597157..55dd3a968f 100644 --- a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java @@ -20,7 +20,7 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; -import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.DmaapClient; +import org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.DmaapClient; public class DmaapClientTestImpl implements DmaapClient { private String correlationId; diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java index ef8fa3dd1e..73b8247ebc 100644 --- a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java @@ -76,7 +76,6 @@ public class PnfEventReadyConsumerTest { testedObject.setDmaapTopicName(EVENT_TOPIC_TEST); testedObject.setConsumerId(CONSUMER_ID); testedObject.setConsumerGroup(CONSUMER_GROUP); - testedObject.setDmaapClientInitialDelayInSeconds(1); testedObject.setDmaapClientDelayInSeconds(1); testedObject.init(); httpClientMock = mock(HttpClient.class); @@ -97,7 +96,7 @@ public class PnfEventReadyConsumerTest { throws IOException { when(httpClientMock.execute(any(HttpGet.class))). thenReturn(createResponse(String.format(JSON_EXAMPLE_WITH_CORRELATION_ID, CORRELATION_ID))); - testedObject.run(); + testedObject.sendRequest(); ArgumentCaptor<HttpGet> captor1 = ArgumentCaptor.forClass(HttpGet.class); verify(httpClientMock).execute(captor1.capture()); assertThat(captor1.getValue().getURI()).hasHost(HOST).hasPort(PORT).hasScheme(PROTOCOL) @@ -120,7 +119,7 @@ public class PnfEventReadyConsumerTest { when(httpClientMock.execute(any(HttpGet.class))). thenReturn(createResponse( String.format(JSON_EXAMPLE_WITH_CORRELATION_ID, CORRELATION_ID_NOT_FOUND_IN_MAP))); - testedObject.run(); + testedObject.sendRequest(); verifyZeroInteractions(threadMockToNotifyCamundaFlow, executorMock); } @@ -134,7 +133,7 @@ public class PnfEventReadyConsumerTest { public void correlationIdIsNotFoundInHttpResponse() throws IOException { when(httpClientMock.execute(any(HttpGet.class))). thenReturn(createResponse(JSON_EXAMPLE_WITH_NO_CORRELATION_ID)); - testedObject.run(); + testedObject.sendRequest(); verifyZeroInteractions(threadMockToNotifyCamundaFlow, executorMock); } diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/client/builder/AbstractBuilderTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/client/builder/AbstractBuilderTest.java index e2ec7e062f..99a87def80 100644 --- a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/client/builder/AbstractBuilderTest.java +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/client/builder/AbstractBuilderTest.java @@ -310,12 +310,12 @@ public class AbstractBuilderTest { abstractBuilder.build(null, null); } - @Test(expected = NullPointerException.class) + @Test public void getRequestActoinTest() throws Exception { abstractBuilder.getRequestActoin(delegateExecution); } - @Test(expected = NullPointerException.class) + @Test public void getSvcActionTest() throws Exception { abstractBuilder.getSvcAction(delegateExecution); } @@ -340,7 +340,7 @@ public class AbstractBuilderTest { abstractBuilder.getParamEntities(new HashMap<>()); } - @Test(expected = NullPointerException.class) + @Test public void getRequestInformationEntityTest() throws Exception { abstractBuilder.getRequestInformationEntity(delegateExecution); } diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIProperties.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIProperties.java index 358bbbbbec..c208d6dd5f 100644 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIProperties.java +++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIProperties.java @@ -25,4 +25,6 @@ import org.openecomp.mso.client.RestProperties; public interface AAIProperties extends RestProperties { public AAIVersion getDefaultVersion(); + public String getAuth(); + public String getKey(); } diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java index 9348beb02a..e36033faa0 100644 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java +++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java @@ -28,22 +28,31 @@ import java.util.UUID; import javax.ws.rs.client.ClientResponseFilter; import javax.ws.rs.ext.ContextResolver; -import org.openecomp.mso.client.RestProperties; import org.openecomp.mso.client.policy.RestClient; import org.openecomp.mso.client.policy.RestClientSSL; import com.fasterxml.jackson.databind.ObjectMapper; public class AAIRestClient extends RestClientSSL { + + private final AAIProperties props; - protected AAIRestClient(RestProperties props, UUID requestId, URI uri) { + protected AAIRestClient(AAIProperties props, UUID requestId, URI uri) { super(props, requestId, Optional.of(uri)); + this.props = props; headerMap.put("X-TransactionId", requestId.toString()); } @Override protected void initializeHeaderMap(Map<String, String> headerMap) { headerMap.put("X-FromAppId", "MSO"); + + String auth = props.getAuth(); + String key = props.getKey(); + + if (auth != null && !auth.isEmpty() && key != null && !key.isEmpty()) { + addBasicAuthHeader(auth, key); + } } @Override diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java index 54aab5c296..a84aeaac8e 100644 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java +++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java @@ -168,7 +168,7 @@ public class AAIRestClientImpl implements AAIRestClientI { try { requestId = UUID.fromString(transactionLoggingUuid); } catch (IllegalArgumentException e) { - logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); + logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically", e); requestId = UUID.randomUUID(); } Response response = new AAIResourcesClient(ENDPOINT_VERSION, requestId) @@ -186,7 +186,7 @@ public class AAIRestClientImpl implements AAIRestClientI { try { requestId = UUID.fromString(transactionLoggingUuid); } catch (IllegalArgumentException e) { - logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); + logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically", e); requestId = UUID.randomUUID(); } new AAIResourcesClient(ENDPOINT_VERSION, requestId) diff --git a/common/src/main/java/org/openecomp/mso/client/defaultproperties/DefaultAAIPropertiesImpl.java b/common/src/main/java/org/openecomp/mso/client/defaultproperties/DefaultAAIPropertiesImpl.java index 354d47af06..3f5bfa97d0 100644 --- a/common/src/main/java/org/openecomp/mso/client/defaultproperties/DefaultAAIPropertiesImpl.java +++ b/common/src/main/java/org/openecomp/mso/client/defaultproperties/DefaultAAIPropertiesImpl.java @@ -65,4 +65,15 @@ public class DefaultAAIPropertiesImpl implements AAIProperties { return AAIVersion.LATEST; } + @Override + public String getAuth() { + Object value = props.get("aai.auth"); + return value == null ? null : value.toString(); + } + + @Override + public String getKey() { + Object value = props.get("mso.msoKey"); + return value == null ? null : value.toString(); + } } diff --git a/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java b/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java index 4e6ffd1c6a..77afe82758 100644 --- a/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java +++ b/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java @@ -23,6 +23,7 @@ package org.openecomp.mso.client.policy; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.security.GeneralSecurityException; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -41,9 +42,11 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.ext.ContextResolver; +import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import org.openecomp.mso.client.RestProperties; import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.utils.CryptoUtils; import org.springframework.stereotype.Service; import com.fasterxml.jackson.databind.ObjectMapper; @@ -84,8 +87,6 @@ public abstract class RestClient { this(props, requestId, path); this.accept = accept; this.contentType = contentType; - this.requestId = requestId; - } protected RestClient(URL host, UUID requestId, String contentType) { @@ -134,6 +135,21 @@ public abstract class RestClient { protected abstract Optional<ClientResponseFilter> addResponseFilter(); public abstract RestClient addRequestId(UUID requestId); + + /** + * Adds a basic authentication header to the request. + * @param auth the encrypted credentials + * @param key the key for decrypting the credentials + */ + protected void addBasicAuthHeader(String auth, String key) { + try { + byte[] decryptedAuth = CryptoUtils.decrypt(auth, key).getBytes(); + String authHeaderValue = "Basic " + new String(Base64.encodeBase64(decryptedAuth)); + headerMap.put("Authorization", authHeaderValue); + } catch (GeneralSecurityException e) { + logger.warn(e.getMessage(), e); + } + } protected ContextResolver<ObjectMapper> getMapper() { return new CommonObjectMapperProvider(); diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java index daf8130cd4..c7cc549130 100644 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java +++ b/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java @@ -78,6 +78,21 @@ public class AAIResourcesClientTest { } @Test + public void verifyBasicAuth() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + wireMockRule.stubFor(get( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) + .withHeader("Authorization", equalTo("Basic TVNPOk1TTw==")) + .willReturn( + aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile("aai/resources/mockObject.json") + .withStatus(200))); + AAIResourcesClient client = new AAIResourcesClient(); + client.get(path); + } + + @Test public void verifyConnect() { AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); diff --git a/common/src/test/resources/aai.properties b/common/src/test/resources/aai.properties index 9d9f1bdce9..897659b332 100644 --- a/common/src/test/resources/aai.properties +++ b/common/src/test/resources/aai.properties @@ -1 +1,3 @@ -aai.endpoint=http://localhost:8443
\ No newline at end of file +aai.endpoint=http://localhost:8443 +aai.auth=2630606608347B7124C244AB0FE34F6F +mso.msoKey=07a7159d3bf51a0e53be7a8f89699be7
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java index 03af038574..92e74e8de2 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java @@ -49,4 +49,14 @@ public class AaiClientPropertiesImpl implements AAIProperties { public AAIVersion getDefaultVersion() { return AAIVersion.LATEST; } + + @Override + public String getAuth() { + return props.getProperty("aai.auth", null); + } + + @Override + public String getKey() { + return props.getProperty("mso.msoKey", null); + } } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java index f69378ec65..9964b93df4 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java @@ -643,13 +643,17 @@ public class RequestsDatabase { msoLogger.debug("Execute query on infra active request table"); OperationStatus operStatus = null; + List<Object> list = null; Session session = sessionFactoryRequestDB.getSessionFactory().openSession(); try { session.beginTransaction(); - String hql = "FROM OperationStatus WHERE SERVICE_ID = :service_id"; + String hql = "FROM OperationStatus WHERE SERVICE_ID = :service_id order by OPERATE_AT desc"; Query query = session.createQuery(hql); query.setParameter("service_id", serviceId); - operStatus = (OperationStatus)query.uniqueResult(); + list = query.list(); + if(list != null && list.size() >= 1) { + operStatus = (OperationStatus) list.get(0); + } } finally { if(session != null && session.isOpen()) { diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestsDatabaseTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestsDatabaseTest.java index 005a28ec52..aacdd96420 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestsDatabaseTest.java +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestsDatabaseTest.java @@ -33,6 +33,7 @@ import org.junit.runner.RunWith; import org.openecomp.mso.db.AbstractSessionFactoryManager; import java.util.Arrays; +import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -237,8 +238,8 @@ public class RequestsDatabaseTest { @Mocked Query query) throws Exception { new Expectations() {{ sessionFactoryManager.getSessionFactory().openSession(); result = session; - session.createQuery("FROM OperationStatus WHERE SERVICE_ID = :service_id"); result = query; - query.uniqueResult(); result = new OperationStatus(); + session.createQuery("FROM OperationStatus WHERE SERVICE_ID = :service_id order by OPERATE_AT desc"); result = query; + List<Object>list = query.list(); result = new OperationStatus(); }}; assertEquals(OperationStatus.class, requestsDatabase.getOperationStatusByServiceId("123").getClass()); |