summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java27
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java9
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoCommonUtils.java2
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java103
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java61
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java54
-rw-r--r--common/src/main/java/org/openecomp/mso/logger/MsoLogger.java46
7 files changed, 213 insertions, 89 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
index d0ba7e09fc..ba9a7d5007 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
@@ -23,28 +23,23 @@
package org.openecomp.mso.cloud;
-import java.io.IOException;
-import java.net.URISyntaxException;
+import com.woorea.openstack.keystone.model.Authentication;
+import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
import java.security.GeneralSecurityException;
-
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.openecomp.mso.openstack.exceptions.MsoAdapterException;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-import org.openecomp.mso.openstack.utils.MsoKeystoneUtils;
-import org.openecomp.mso.openstack.utils.MsoTenantUtils;
-import org.openecomp.mso.openstack.utils.MsoTenantUtilsFactory;
import org.openecomp.mso.cloud.authentication.AuthenticationMethodFactory;
import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;
import org.openecomp.mso.cloud.authentication.wrappers.UsernamePasswordWrapper;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
-
-import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.utils.MsoKeystoneUtils;
+import org.openecomp.mso.openstack.utils.MsoTenantUtils;
+import org.openecomp.mso.openstack.utils.MsoTenantUtilsFactory;
import org.openecomp.mso.utils.CryptoUtils;
-import com.woorea.openstack.keystone.model.Authentication;
/**
* JavaBean JSON class for a CloudIdentity. This bean represents a cloud identity
@@ -143,15 +138,11 @@ public class CloudIdentity {
}
}
}
-
- public Authentication getAuthentication () throws MsoException {
+
+ public Authentication getAuthentication() {
if (this.getIdentityAuthenticationType() != null) {
- try {
return AuthenticationMethodFactory.getAuthenticationFor(this);
- } catch (IllegalAccessException | InstantiationException | ClassNotFoundException | IOException | URISyntaxException e) {
- throw new MsoAdapterException("Could not retrieve authentication for " + this.identityAuthenticationType, e);
- }
- } else { // Fallback
+ } else {
return new UsernamePassword(this.getMsoId(), this.getMsoPass());
}
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java
index 85cb2967d6..c9be2c7949 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java
@@ -23,18 +23,13 @@
package org.openecomp.mso.cloud.authentication;
-import java.io.IOException;
-import java.net.URISyntaxException;
+import com.woorea.openstack.keystone.model.Authentication;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-
import org.openecomp.mso.cloud.CloudIdentity;
-import com.woorea.openstack.keystone.model.Authentication;
-
/**
* This factory manages all the wrappers associated to authentication types.
- *
*/
public final class AuthenticationMethodFactory {
@@ -58,7 +53,7 @@ public final class AuthenticationMethodFactory {
}
}
- public static final synchronized Authentication getAuthenticationFor(CloudIdentity cloudIdentity) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, URISyntaxException {
+ public static final synchronized Authentication getAuthenticationFor(CloudIdentity cloudIdentity) {
if (cloudIdentity == null) {
throw new IllegalArgumentException("Cloud identity cannot be null");
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoCommonUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoCommonUtils.java
index 269f6b0cdf..7d6de317ad 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoCommonUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoCommonUtils.java
@@ -129,6 +129,7 @@ public class MsoCommonUtils {
Thread.sleep (retryDelay * 1000L);
} catch (InterruptedException e1) {
logger.debug ("Thread interrupted while sleeping", e1);
+ Thread.currentThread().interrupt();
}
}
else
@@ -144,6 +145,7 @@ public class MsoCommonUtils {
Thread.sleep (retryDelay * 1000L);
} catch (InterruptedException e1) {
logger.debug ("Thread interrupted while sleeping", e1);
+ Thread.currentThread().interrupt();
}
}
else
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java
new file mode 100644
index 0000000000..2cfce276d8
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java
@@ -0,0 +1,103 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * 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============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.woorea.openstack.keystone.model.Authentication;
+import org.junit.Test;
+import org.openecomp.mso.cloud.CloudIdentity;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityAuthenticationType;
+import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;
+
+public class AuthenticationMethodFactoryTest {
+
+ private static final Class WRAPPER_CLASS = RackspaceAPIKeyWrapper.class;
+ private static final String AUTHENTICATION_TYPE = "authenticationTest";
+
+ @Test
+ public void register_NoExceptionThrown() throws IllegalAccessException, InstantiationException {
+ AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, WRAPPER_CLASS);
+ }
+
+ @Test
+ public void register_throwExceptionWhenAuthTypeIsNull() throws InstantiationException, IllegalAccessException {
+ try {
+ AuthenticationMethodFactory.register(null, WRAPPER_CLASS);
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null "
+ + "or an empty name string");
+ }
+ }
+
+ @Test
+ public void register_throwExceptionWhenAuthTypeIsEmpty() throws InstantiationException, IllegalAccessException {
+ try {
+ AuthenticationMethodFactory.register("", WRAPPER_CLASS);
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null "
+ + "or an empty name string");
+ }
+ }
+
+ @Test
+ public void register_throwExceptionWhenWrapperIsNull() throws IllegalAccessException, InstantiationException {
+ try {
+ AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, null);
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty()
+ .contains("Wrapper Class to register for Authentication cannot be null");
+ }
+ }
+
+ @Test
+ public void getAuthentication_NoExceptionThrown() {
+ CloudIdentity cloudIdentity = new CloudIdentity();
+ cloudIdentity.setIdentityAuthenticationType(IdentityAuthenticationType.RACKSPACE_APIKEY);
+ cloudIdentity.setMsoId("msoIdTest");
+ cloudIdentity.setMsoPass("123");
+ Authentication result = AuthenticationMethodFactory.getAuthenticationFor(cloudIdentity);
+ assertThat(result).isNotNull();
+ }
+
+ @Test
+ public void getAuthentication_ThrowExWhenCloudSiteIsNull() {
+ try {
+ AuthenticationMethodFactory.getAuthenticationFor(null);
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty().contains("Cloud identity cannot be null");
+ }
+ }
+
+ @Test
+ public void getAuthentication_ThrowExWhenIdentityAuthenticationTypeIsNotSet() {
+ try {
+ AuthenticationMethodFactory.getAuthenticationFor(new CloudIdentity());
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty()
+ .contains("Cloud identity authentication type cannot be null or empty");
+ }
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java
index ccfede7297..b6c1c7373f 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java
@@ -25,16 +25,11 @@ package org.openecomp.mso.cloud.authentication;
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
+import com.woorea.openstack.keystone.model.Authentication;
+import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
import org.junit.Test;
import org.openecomp.mso.cloud.CloudIdentity;
import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-
-import com.woorea.openstack.keystone.model.Authentication;
-import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
/**
* A few JUnit tests to evaluate the new factory that manages authentication
@@ -50,52 +45,15 @@ public class AuthenticationMethodTest {
public AuthenticationMethodTest() {
// TODO Auto-generated constructor stub
}
-
- @Test
- public void testCustomRackspaceAuth() {
- CloudIdentity ci = new CloudIdentity();
- ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
- ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
- ci.setMsoId("test");
-
- try {
- Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);
- assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
- | URISyntaxException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testCoreUsernamePasswordAuth() {
- CloudIdentity ci = new CloudIdentity();
- ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
- ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
- ci.setMsoId("someuser");
-
- try {
- Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);
- assertTrue(UsernamePassword.class.equals(auth.getClass()));
- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
- | URISyntaxException e) {
- e.printStackTrace();
- }
- }
-
+
@Test
public void testCustomRackspaceAuthFromCloudIdentity() {
CloudIdentity ci = new CloudIdentity();
ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
ci.setMsoId("test");
-
- try {
- Authentication auth = ci.getAuthentication();
- assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
- } catch (MsoException e) {
- e.printStackTrace();
- }
+ Authentication auth = ci.getAuthentication();
+ assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
}
@Test
@@ -104,12 +62,7 @@ public class AuthenticationMethodTest {
ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
ci.setMsoId("someuser");
-
- try {
- Authentication auth = ci.getAuthentication();
- assertTrue(UsernamePassword.class.equals(auth.getClass()));
- } catch (MsoException e) {
- e.printStackTrace();
- }
+ Authentication auth = ci.getAuthentication();
+ assertTrue(UsernamePassword.class.equals(auth.getClass()));
}
}
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java
new file mode 100644
index 0000000000..fa96b7983e
--- /dev/null
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============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.adapters.sdnc;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openecomp.mso.adapters.sdnc.SDNCAdapterRequest;
+import org.openecomp.mso.adapters.sdnc.RequestHeader;
+
+
+public class SDNCAdapterRequestTest {
+
+ static Object sd= new SDNCAdapterRequest();
+ static RequestHeader rh=new RequestHeader();
+
+ @BeforeClass
+ public static final void RHeader()
+ {
+ rh.setCallbackUrl("callback");
+ rh.setMsoAction ("action");
+ rh.setRequestId ("reqid");
+ rh.setSvcAction ("svcAction");
+ rh.setSvcInstanceId ("svcId");
+ rh.setSvcOperation ("op");
+ }
+ @Test
+ public final void testtoString(){
+ ((SDNCAdapterRequest) sd).setRequestData("data");
+ ((SDNCAdapterRequest) sd).setRequestHeader(rh);
+ assert (((SDNCAdapterRequest) sd).getRequestData()!= null) ;
+ assert(((SDNCAdapterRequest) sd).getRequestData().equals("data"));
+ assert(((SDNCAdapterRequest) sd).getRequestHeader().equals(rh));
+ }
+
+}
diff --git a/common/src/main/java/org/openecomp/mso/logger/MsoLogger.java b/common/src/main/java/org/openecomp/mso/logger/MsoLogger.java
index 86aedc1a43..b8c4aed8fa 100644
--- a/common/src/main/java/org/openecomp/mso/logger/MsoLogger.java
+++ b/common/src/main/java/org/openecomp/mso/logger/MsoLogger.java
@@ -144,15 +144,16 @@ public class MsoLogger {
// For internal logging of the initialization of MSO logs
private static final Logger LOGGER = Logger.getLogger(MsoLogger.class.getName());
- private MsoLogger(MsoLogger.Catalog cat) {
- this.logger = EELFManager.getInstance().getErrorLogger();
- this.auditLogger = EELFManager.getInstance().getAuditLogger();
- this.metricsLogger = EELFManager.getInstance().getMetricsLogger();
- MsoLogger.initialization();
- setDefaultLogCatalog(cat);
- }
- private static synchronized void initialization() {
+ // Since four adaptors are using the instance of MsoLogger which will be referenced everywhere
+ // hence limiting the number of MsoLogger instances to five.
+ private static final MsoLogger generalMsoLogger = new MsoLogger(Catalog.GENERAL);
+ private static final MsoLogger apihLogger = new MsoLogger(Catalog.APIH);
+ private static final MsoLogger asdcLogger = new MsoLogger(Catalog.ASDC);
+ private static final MsoLogger raLogger = new MsoLogger(Catalog.RA);
+ private static final MsoLogger bpelLogger = new MsoLogger(Catalog.BPEL);
+
+ static {
if (instanceUUID == null || ("").equals(instanceUUID)) {
instanceUUID = getInstanceUUID();
}
@@ -170,15 +171,40 @@ public class MsoLogger {
}
}
+ // Singleton instances of the EELFLogger of all types are referenced by MsoLogger
+ private MsoLogger(Catalog cat) {
+ this.logger = EELFManager.getInstance().getErrorLogger();
+ this.auditLogger = EELFManager.getInstance().getAuditLogger();
+ this.metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ this.setDefaultLogCatalog(cat);
+ }
+
+
+
/**
* Get the MsoLogger based on the catalog
- *
+ * This method is fixed now to resolve the total number of objects that are getting created
+ * everytime this function gets called. Its supposed to have fixed number of instance per java process.
+ *
* @param cat
* Catalog of the logger
* @return the MsoLogger
*/
public static synchronized MsoLogger getMsoLogger(MsoLogger.Catalog cat) {
- return new MsoLogger(cat);
+ switch (cat) {
+ case GENERAL:
+ return generalMsoLogger;
+ case APIH:
+ return apihLogger;
+ case RA:
+ return raLogger;
+ case BPEL:
+ return bpelLogger;
+ case ASDC:
+ return asdcLogger;
+ default:
+ return generalMsoLogger;
+ }
}
/**