diff options
Diffstat (limited to 'common')
13 files changed, 243 insertions, 45 deletions
diff --git a/common/pom.xml b/common/pom.xml index ab498f8844..08554480c3 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -1,11 +1,11 @@ -<?xml version="1.0"?> +<?xml version="1.0" ?> <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> <parent> <groupId>org.onap.so</groupId> <artifactId>so</artifactId> - <version>1.6.0-SNAPSHOT</version> + <version>1.7.1-SNAPSHOT</version> </parent> <artifactId>common</artifactId> <name>MSO Common classes</name> @@ -58,7 +58,7 @@ <dependency> <groupId>org.modelmapper</groupId> <artifactId>modelmapper</artifactId> - <version>1.1.0</version> + <version>2.3.2</version> </dependency> <dependency> <groupId>com.google.guava</groupId> @@ -109,6 +109,10 @@ <optional>true</optional> </dependency> <dependency> + <groupId>org.springframework.retry</groupId> + <artifactId>spring-retry</artifactId> + </dependency> + <dependency> <groupId>net.jodah</groupId> <artifactId>failsafe</artifactId> <version>2.0.1</version> @@ -133,12 +137,16 @@ <dependency> <groupId>org.onap.aaf.authz</groupId> <artifactId>aaf-cadi-aaf</artifactId> - <version>2.1.9</version> + <version>${aaf.cadi.version}</version> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> </exclusions> </dependency> <dependency> @@ -262,6 +270,21 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>2.3.0</version> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-core</artifactId> + <version>2.3.0</version> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>2.3.0</version> + </dependency> </dependencies> <dependencyManagement> <dependencies> @@ -335,4 +358,4 @@ </plugin> </plugins> </build> -</project> +</project>
\ No newline at end of file diff --git a/common/src/main/java/org/onap/so/appc/orchestrator/service/beans/ApplicationControllerTaskRequest.java b/common/src/main/java/org/onap/so/appc/orchestrator/service/beans/ApplicationControllerTaskRequest.java index c240957ae9..010e184618 100644 --- a/common/src/main/java/org/onap/so/appc/orchestrator/service/beans/ApplicationControllerTaskRequest.java +++ b/common/src/main/java/org/onap/so/appc/orchestrator/service/beans/ApplicationControllerTaskRequest.java @@ -11,6 +11,7 @@ public class ApplicationControllerTaskRequest implements Serializable { private static final long serialVersionUID = -3150320542857627682L; private Action action; + private String requestorId; private String controllerType; private String identityUrl; private String operationsTimeout; @@ -110,6 +111,14 @@ public class ApplicationControllerTaskRequest implements Serializable { this.newSoftwareVersion = newSoftwareVersion; } + public String getRequestorId() { + return requestorId; + } + + public void setRequestorId(String requestorId) { + this.requestorId = requestorId; + } + } diff --git a/common/src/main/java/org/onap/so/client/KeyStoreLoader.java b/common/src/main/java/org/onap/so/client/KeyStoreLoader.java new file mode 100644 index 0000000000..8279be8635 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/KeyStoreLoader.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Deutsche Telekom. + * ================================================================================ + * 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.client; + +import java.io.FileInputStream; +import java.nio.file.Paths; +import java.security.KeyStore; + +public abstract class KeyStoreLoader { + + static final String SSL_KEY_STORE_KEY = "javax.net.ssl.keyStore"; + + static public KeyStore getKeyStore() { + KeyStore ks = null; + final char[] password = getSSlKeyStorePassword().toCharArray(); + try (FileInputStream fis = + new FileInputStream(Paths.get(System.getProperty(SSL_KEY_STORE_KEY)).normalize().toString())) { + ks = KeyStore.getInstance(KeyStore.getDefaultType()); + ks.load(fis, password); + } catch (final Exception e) { + return null; + } + + return ks; + } + + static public String getSSlKeyStorePassword() { + return System.getProperty("javax.net.ssl.keyStorePassword"); + } +} diff --git a/common/src/main/java/org/onap/so/client/RestClientSSL.java b/common/src/main/java/org/onap/so/client/RestClientSSL.java index f5737b862c..1e8953892e 100644 --- a/common/src/main/java/org/onap/so/client/RestClientSSL.java +++ b/common/src/main/java/org/onap/so/client/RestClientSSL.java @@ -20,9 +20,7 @@ package org.onap.so.client; -import java.io.FileInputStream; import java.net.URI; -import java.nio.file.Paths; import java.security.KeyStore; import java.security.NoSuchAlgorithmException; import java.util.Optional; @@ -33,10 +31,8 @@ import javax.ws.rs.client.ClientBuilder; public abstract class RestClientSSL extends RestClient { private static final String TRUE = "true"; - private static final String SSL_KEY_STORE_KEY = "javax.net.ssl.keyStore"; private static final String MSO_LOAD_SSL_CLIENT_KEYSTORE_KEY = "mso.load.ssl.client.keystore"; - protected RestClientSSL(RestProperties props, Optional<URI> path) { super(props, path); } @@ -52,9 +48,9 @@ public abstract class RestClientSSL extends RestClient { try { String loadSSLKeyStore = System.getProperty(RestClientSSL.MSO_LOAD_SSL_CLIENT_KEYSTORE_KEY); if (loadSSLKeyStore != null && loadSSLKeyStore.equalsIgnoreCase(TRUE)) { - KeyStore ks = getKeyStore(); + KeyStore ks = KeyStoreLoader.getKeyStore(); if (ks != null) { - client = ClientBuilder.newBuilder().keyStore(ks, getSSlKeyStorePassword()).build(); + client = ClientBuilder.newBuilder().keyStore(ks, KeyStoreLoader.getSSlKeyStorePassword()).build(); logger.info("RestClientSSL not using default SSL context - setting keystore here."); return client; } @@ -67,23 +63,4 @@ public abstract class RestClientSSL extends RestClient { } return client; } - - private KeyStore getKeyStore() { - KeyStore ks = null; - char[] password = getSSlKeyStorePassword().toCharArray(); - try (FileInputStream fis = new FileInputStream( - Paths.get(System.getProperty(RestClientSSL.SSL_KEY_STORE_KEY)).normalize().toString())) { - ks = KeyStore.getInstance(KeyStore.getDefaultType()); - - ks.load(fis, password); - } catch (Exception e) { - return null; - } - - return ks; - } - - private String getSSlKeyStorePassword() { - return System.getProperty("javax.net.ssl.keyStorePassword"); - } } diff --git a/common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java b/common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java index 7ef158996d..fa309b54fe 100644 --- a/common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java +++ b/common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 - 2019 Bell Canada. + * Copyright (C) 2017 - 2019 Bell Canada, Deutsche Telekom. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,16 @@ package org.onap.so.client.cds; import io.grpc.ManagedChannel; import io.grpc.internal.DnsNameResolverProvider; import io.grpc.internal.PickFirstLoadBalancerProvider; +import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NettyChannelBuilder; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.CountDownLatch; +import javax.net.ssl.SSLException; +import javax.net.ssl.TrustManagerFactory; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; +import org.onap.so.client.KeyStoreLoader; import org.onap.so.client.PreconditionFailedException; import org.onap.so.client.RestPropertiesLoader; import org.slf4j.Logger; @@ -73,10 +80,36 @@ public class CDSProcessingClient implements AutoCloseable { throw new PreconditionFailedException( "No RestProperty.CDSProperties implementation found on classpath, can't create client."); } - this.channel = NettyChannelBuilder.forAddress(props.getHost(), props.getPort()) + NettyChannelBuilder builder = NettyChannelBuilder.forAddress(props.getHost(), props.getPort()) .nameResolverFactory(new DnsNameResolverProvider()) - .loadBalancerFactory(new PickFirstLoadBalancerProvider()) - .intercept(new BasicAuthClientInterceptor(props)).usePlaintext().build(); + .loadBalancerFactory(new PickFirstLoadBalancerProvider()); + if (props.getUseSSL()) { + log.info("Configure SSL connection"); + KeyStore ks = KeyStoreLoader.getKeyStore(); + if (ks == null) { + log.error("Can't load KeyStore"); + throw new RuntimeException("Can't load KeyStore to create secure channel"); + } + try { + TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + tmf.init(ks); + builder.sslContext(GrpcSslContexts.forClient().trustManager(tmf).build()); + } catch (NoSuchAlgorithmException e) { + log.error("Can't get default TrustManager algorithm"); + throw new RuntimeException(e); + } catch (KeyStoreException e) { + log.error("TrustManagerFactory initialization failed"); + throw new RuntimeException(e); + } catch (SSLException e) { + log.error("SslContext build error"); + throw new RuntimeException(e); + } + } + if (props.getUseBasicAuth()) { + log.info("Configure Basic authentication"); + builder.intercept(new BasicAuthClientInterceptor(props)).usePlaintext(); + } + this.channel = builder.build(); this.handler = new CDSProcessingHandler(listener); log.info("CDSProcessingClient started"); } diff --git a/common/src/main/java/org/onap/so/client/cds/CDSProperties.java b/common/src/main/java/org/onap/so/client/cds/CDSProperties.java index 37a5c0bc18..db566fa3de 100644 --- a/common/src/main/java/org/onap/so/client/cds/CDSProperties.java +++ b/common/src/main/java/org/onap/so/client/cds/CDSProperties.java @@ -22,7 +22,6 @@ package org.onap.so.client.cds; import org.onap.so.client.RestProperties; - public interface CDSProperties extends RestProperties { String getHost(); @@ -32,4 +31,8 @@ public interface CDSProperties extends RestProperties { String getBasicAuth(); int getTimeout(); + + boolean getUseSSL(); + + boolean getUseBasicAuth(); } diff --git a/common/src/main/java/org/onap/so/client/exception/BadResponseException.java b/common/src/main/java/org/onap/so/client/exception/BadResponseException.java new file mode 100644 index 0000000000..7b1066d48c --- /dev/null +++ b/common/src/main/java/org/onap/so/client/exception/BadResponseException.java @@ -0,0 +1,42 @@ +/*- + * ============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.onap.so.client.exception; + +public class BadResponseException extends Exception { + + String responseCode; + + public BadResponseException() {} + + public BadResponseException(String message) { + super(message); + } + + public BadResponseException(String message, String responseCode) { + super(message); + this.responseCode = responseCode; + } + + public String getResponseCode() { + return responseCode; + } + +} diff --git a/common/src/main/java/org/onap/so/client/exception/MapperException.java b/common/src/main/java/org/onap/so/client/exception/MapperException.java new file mode 100644 index 0000000000..354c669d62 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/exception/MapperException.java @@ -0,0 +1,31 @@ +/*- + * ============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.onap.so.client.exception; + +public class MapperException extends Exception { + + public MapperException() {} + + public MapperException(String message) { + super(message); + } + +} diff --git a/common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java b/common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java index 6e2bc97ee9..84efa65a50 100644 --- a/common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java +++ b/common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java @@ -31,6 +31,8 @@ import java.util.List; import java.util.Set; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import org.hamcrest.Matcher; import com.openpojo.business.annotation.BusinessKey; import com.openpojo.random.RandomFactory; @@ -42,7 +44,6 @@ import com.openpojo.validation.utils.ValidationHelper; public class EqualsAndHashCodeTester implements Tester { - private final Matcher m; private boolean onlyDeclaredMethods = false; @@ -118,7 +119,6 @@ public class EqualsAndHashCodeTester implements Tester { } } - private Set<PojoField> hasIdOrBusinessKey(PojoClass pojoClass) { final Set<PojoField> fields = new HashSet<>(); diff --git a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java index 840a978a61..fff82ea5bc 100644 --- a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java +++ b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java @@ -22,8 +22,16 @@ public class ExternalTaskServiceUtils { @Autowired public Environment env; - protected Set<ExternalTaskClient> taskClients = ConcurrentHashMap.newKeySet(); + private static final long DEFAULT_LOCK_DURATION_LONG = 2700000; + private static final long DEFAULT_LOCK_DURATION_MEDIUM = 900000; + private static final long DEFAULT_LOCK_DURATION_SHORT = 300000; + + private static final String LOCK_DURATION_LONG = "mso.workflow.topics.lockDurationLong"; + private static final String LOCK_DURATION_MEDIUM = "mso.workflow.topics.lockDurationMedium"; + private static final String LOCK_DURATION_SHORT = "mso.workflow.topics.lockDurationShort"; + + protected Set<ExternalTaskClient> taskClients = ConcurrentHashMap.newKeySet(); private static final Logger logger = LoggerFactory.getLogger(ExternalTaskServiceUtils.class); @@ -59,6 +67,11 @@ public class ExternalTaskServiceUtils { return lockDuration; } + public Long getLongLockDuration() { + Long lockDuration = Long.parseLong(env.getProperty("mso.long.lock-time", "600000")); + return lockDuration; + } + @ScheduledLogging @Scheduled(fixedDelay = 30000) public void checkAllClientsActive() { @@ -69,4 +82,16 @@ public class ExternalTaskServiceUtils { return taskClients; } + public long getLockDurationLong() { + return env.getProperty(LOCK_DURATION_LONG, Long.class, new Long(DEFAULT_LOCK_DURATION_LONG)); + } + + public long getLockDurationMedium() { + return env.getProperty(LOCK_DURATION_MEDIUM, Long.class, new Long(DEFAULT_LOCK_DURATION_MEDIUM)); + } + + public long getLockDurationShort() { + return env.getProperty(LOCK_DURATION_SHORT, Long.class, new Long(DEFAULT_LOCK_DURATION_SHORT)); + } + } diff --git a/common/src/test/java/org/onap/so/client/HttpClientTest.java b/common/src/test/java/org/onap/so/client/HttpClientTest.java index a01e2bb812..e9e8fe7853 100644 --- a/common/src/test/java/org/onap/so/client/HttpClientTest.java +++ b/common/src/test/java/org/onap/so/client/HttpClientTest.java @@ -40,7 +40,7 @@ public class HttpClientTest { private final HttpClientFactory httpClientFactory = new HttpClientFactory(); @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicHttpsPort()); + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort().dynamicHttpsPort()); @Test public void testPost_success() throws MalformedURLException { @@ -48,7 +48,7 @@ public class HttpClientTest { wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(""))); - URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); HttpClient client = httpClientFactory.newJsonClient(url, ONAPComponents.BPMN); client.addBasicAuthHeader( @@ -67,7 +67,7 @@ public class HttpClientTest { wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(""))); - URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); HttpClient client = httpClientFactory.newJsonClient(url, ONAPComponents.BPMN); client.addAdditionalHeader("Accept", "application/json"); @@ -85,7 +85,7 @@ public class HttpClientTest { wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(""))); - URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); HttpClient client = httpClientFactory.newJsonClient(url, ONAPComponents.BPMN); client.addBasicAuthHeader("", "12345"); diff --git a/common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java b/common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java index 18ec9efa50..5792c28f5f 100644 --- a/common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java +++ b/common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java @@ -20,7 +20,6 @@ package org.onap.so.client.cds; - import static org.junit.Assert.*; import static org.mockito.Mockito.*; import io.grpc.inprocess.InProcessChannelBuilder; @@ -58,7 +57,6 @@ public class CDSProcessingClientTest { private CDSProcessingHandler handler; private CDSProcessingClient client; - private final MutableHandlerRegistry serviceRegistry = new MutableHandlerRegistry(); private final List<String> messagesDelivered = new ArrayList<>(); private final CountDownLatch allRequestsDelivered = new CountDownLatch(1); @@ -115,7 +113,6 @@ public class CDSProcessingClientTest { new CDSProcessingClient(listener); } - @Test public void testSendMessageFail() throws Exception { diff --git a/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java b/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java index 2834d37f1f..41238e539e 100644 --- a/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java +++ b/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java @@ -72,4 +72,14 @@ public class TestCDSPropertiesImpl implements CDSProperties { public int getTimeout() { return 60; } + + @Override + public boolean getUseSSL() { + return false; + } + + @Override + public boolean getUseBasicAuth() { + return true; + } } |