From 2e971ba4b99e987a18237675e50adc4a5f21d0d6 Mon Sep 17 00:00:00 2001 From: "Kajur, Harish (vk250x)" Date: Wed, 10 Apr 2019 15:43:25 -0400 Subject: Make changes to integrate latest changes Add perm flags with metaspace flags as permgen has been replaced by metaspace in java 8 Update junits to remove the certificate Fix password configruation and schema changes to work with the increase nodes tool Correct service.name for making sure the correct DB connection name is set Add aaiconfig properties for the deleted objects to log Issue-ID: AAI-2327 Change-Id: I5a8a70f6d6630960b0e8ec4780fce3e1baf79cc1 Signed-off-by: Kajur, Harish (vk250x) --- aai-resources/src/main/docker/Dockerfile | 2 +- aai-resources/src/main/docker/docker-entrypoint.sh | 7 +- .../main/java/org/onap/aai/IncreaseNodesTool.java | 97 ++++++++++++----- .../src/main/java/org/onap/aai/ResourcesApp.java | 3 +- .../resources/etc/appprops/aaiconfig.properties | 10 +- aai-resources/src/main/resources/logback.xml | 119 ++++----------------- .../org/onap/aai/ResourcesTestConfiguration.java | 42 ++++---- .../org/onap/aai/rest/AbstractSpringRestTest.java | 2 +- .../java/org/onap/aai/rest/ConfigurationTest.java | 2 +- .../onap/aai/rest/CustomerFilterSearchTest.java | 2 +- .../java/org/onap/aai/rest/PserverMissingTest.java | 4 +- .../src/test/resources/application-test.properties | 18 ++-- 12 files changed, 147 insertions(+), 161 deletions(-) (limited to 'aai-resources/src') diff --git a/aai-resources/src/main/docker/Dockerfile b/aai-resources/src/main/docker/Dockerfile index ec38c02..e6d9d6f 100644 --- a/aai-resources/src/main/docker/Dockerfile +++ b/aai-resources/src/main/docker/Dockerfile @@ -9,7 +9,7 @@ WORKDIR /opt/app/aai-resources EXPOSE 8447 -HEALTHCHECK --interval=40s --timeout=10s --retries=3 CMD nc -z -v localhost 8447 || exit 1 +HEALTHCHECK --interval=40s --timeout=10s --retries=3 CMD nc -z -v localhost ${SERVER_PORT:-8447} || exit 1 ENTRYPOINT ["/bin/bash", "/opt/app/aai-resources/docker-entrypoint.sh"] diff --git a/aai-resources/src/main/docker/docker-entrypoint.sh b/aai-resources/src/main/docker/docker-entrypoint.sh index d2fe989..418fb26 100644 --- a/aai-resources/src/main/docker/docker-entrypoint.sh +++ b/aai-resources/src/main/docker/docker-entrypoint.sh @@ -90,8 +90,7 @@ fi; MIN_HEAP_SIZE=${MIN_HEAP_SIZE:-512m}; MAX_HEAP_SIZE=${MAX_HEAP_SIZE:-1024m}; -MAX_PERM_SIZE=${MAX_PERM_SIZE:-512m}; -PERM_SIZE=${PERM_SIZE:-512m}; +MAX_METASPACE_SIZE=${MAX_METASPACE_SIZE:-512m}; JAVA_CMD="exec gosu aaiadmin java"; @@ -102,8 +101,7 @@ JVM_OPTS="${JVM_OPTS} -Xmx${MAX_HEAP_SIZE}"; JVM_OPTS="${JVM_OPTS} -XX:+PrintGCDetails"; JVM_OPTS="${JVM_OPTS} -XX:+PrintGCTimeStamps"; -JVM_OPTS="${JVM_OPTS} -XX:MaxPermSize=${MAX_PERM_SIZE}"; -JVM_OPTS="${JVM_OPTS} -XX:PermSize=${PERM_SIZE}"; +JVM_OPTS="${JVM_OPTS} -XX:MaxMetaspaceSize=${MAX_METASPACE_SIZE}"; JVM_OPTS="${JVM_OPTS} -server"; JVM_OPTS="${JVM_OPTS} -XX:NewSize=512m"; @@ -138,6 +136,7 @@ JAVA_OPTS="${JAVA_OPTS} -DAAI_BUILD_VERSION=${AAI_BUILD_VERSION}"; JAVA_OPTS="${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom"; JAVA_OPTS="${JAVA_OPTS} -Dlogback.configurationFile=./resources/logback.xml"; JAVA_OPTS="${JAVA_OPTS} -Dloader.path=$APP_HOME/resources"; +JAVA_OPTS="${JAVA_OPTS} -Dgroovy.use.classvalue=true"; JAVA_OPTS="${JAVA_OPTS} ${POST_JAVA_OPTS}"; JAVA_MAIN_JAR=$(ls lib/aai-resources*.jar); diff --git a/aai-resources/src/main/java/org/onap/aai/IncreaseNodesTool.java b/aai-resources/src/main/java/org/onap/aai/IncreaseNodesTool.java index a4c6ef5..23814bf 100644 --- a/aai-resources/src/main/java/org/onap/aai/IncreaseNodesTool.java +++ b/aai-resources/src/main/java/org/onap/aai/IncreaseNodesTool.java @@ -23,16 +23,26 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import java.util.UUID; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.springframework.context.ApplicationContext; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphTransaction; +import org.onap.aai.config.PropertyPasswordConfiguration; +import org.onap.aai.config.SpringContextAware; import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.exceptions.AAIUnknownObjectException; +import org.onap.aai.logging.ErrorLogHelper; +import org.onap.aai.logging.LoggingContext; import org.onap.aai.setup.SchemaVersions; import org.onap.aai.util.AAISystemExitUtil; import org.onap.aai.util.PositiveNumValidator; @@ -41,35 +51,56 @@ import org.onap.aai.serialization.db.EdgeSerializer; import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.beans.factory.annotation.Autowired; public class IncreaseNodesTool { public static long nodeCount = 0; - protected EdgeSerializer edgeSerializer; + + @Autowired + protected static EdgeSerializer edgeSerializer; + private LoaderFactory loaderFactory; private SchemaVersions schemaVersions; protected TransactionalGraphEngine engine; Vertex parentVtx; - + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(IncreaseNodesTool.class); public IncreaseNodesTool(LoaderFactory loaderFactory, SchemaVersions schemaVersions){ this.loaderFactory = loaderFactory; this.schemaVersions = schemaVersions; } - public static void main(String[] args) throws AAIUnknownObjectException, UnsupportedEncodingException { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( - "org.onap.aai.config", - "org.onap.aai.setup" - ); + public static void main(String[] args) throws AAIUnknownObjectException, UnsupportedEncodingException, AAIException { + + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + PropertyPasswordConfiguration initializer = new PropertyPasswordConfiguration(); + initializer.initialize(context); + try { + context.scan( + "org.onap.aai.config", + "org.onap.aai.setup" + ); + context.refresh(); + } catch (Exception e) { + AAIException aai = ResourcesApp.schemaServiceExceptionTranslator(e); + LOGGER.error("Problems running the tool "+aai.getMessage()); + LoggingContext.statusCode(LoggingContext.StatusCode.ERROR); + LoggingContext.responseCode(LoggingContext.DATA_ERROR); + ErrorLogHelper.logError(aai.getCode(), e.getMessage() + ", resolve and retry"); + throw aai; + } LoaderFactory loaderFactory = context.getBean(LoaderFactory.class); - SchemaVersions schemaVersions = context.getBean(SchemaVersions.class); + SchemaVersions schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions"); IncreaseNodesTool increaseNodesTool = new IncreaseNodesTool(loaderFactory, schemaVersions); JanusGraph janusGraph = AAIGraph.getInstance().getGraph(); + + ApplicationContext ctx = (ApplicationContext) SpringContextAware.getApplicationContext(); + edgeSerializer = ctx.getBean(EdgeSerializer.class); + increaseNodesTool.run(janusGraph,args); AAISystemExitUtil.systemExitCloseAAIGraph(0); @@ -111,22 +142,7 @@ public class IncreaseNodesTool { for (long i = 1; i <= nodeCount; i++) { String randomId = UUID.randomUUID().toString(); Vertex v = g.addV().next(); - - if(cArgs.child.equals(true)){ - - if(parentVtx == null){ - String[] uriTokens = cArgs.uri.split("//"); - String ParentNodeType = uriTokens[uriTokens.length-4]; //parent node type - String keyVal = uriTokens[uriTokens.length-3]; // parent unique key - parentVtx = g.V().has(ParentNodeType,keyVal).next(); - edgeSerializer.addTreeEdgeIfPossible(g,parentVtx,v); - - } - else{ - edgeSerializer.addTreeEdgeIfPossible(g,parentVtx,v); - } - } - + v.property("aai-node-type", nodeType); v.property("source-of-truth", "IncreaseNodesTool"); v.property("aai-uri", cArgs.uri+"random-"+randomId); @@ -135,10 +151,41 @@ public class IncreaseNodesTool { for(String propName : propList){ if(propName.equals("in-maint")){ v.property(propName,"false"); + continue; } v.property(propName, "random-" + randomId); System.out.println("node " + i + " added " + propList.get(0)+": " + "random-"+randomId); } + + if(cArgs.child.equals("true")){ + + if(parentVtx == null){ + String[] uriTokens = cArgs.uri.split("/"); + String ParentNodeType = uriTokens[uriTokens.length-4]; //parent node type + String keyVal = uriTokens[uriTokens.length-3]; // parent unique key + Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + if (loader != null) + { + Introspector objParent = loader.introspectorFromName(ParentNodeType); + if (objParent != null) + { + List parentPropList = new ArrayList(); + parentPropList.addAll(objParent.getRequiredProperties()); + if (parentPropList.size() > 0) + { + System.out.println("parent node (" + ParentNodeType + ") key (" + parentPropList.get(0)+" ) =" + keyVal); + parentVtx = g.V().has(parentPropList.get(0),keyVal).next(); + edgeSerializer.addTreeEdgeIfPossible(g,parentVtx,v); + } + } + } + + } + else{ + edgeSerializer.addTreeEdgeIfPossible(g,parentVtx,v); + } + } + } } catch (Exception ex) { success = false; diff --git a/aai-resources/src/main/java/org/onap/aai/ResourcesApp.java b/aai-resources/src/main/java/org/onap/aai/ResourcesApp.java index 36fcd41..f653487 100644 --- a/aai-resources/src/main/java/org/onap/aai/ResourcesApp.java +++ b/aai-resources/src/main/java/org/onap/aai/ResourcesApp.java @@ -188,6 +188,7 @@ public class ResourcesApp { } String currentDirectory = System.getProperty("user.dir"); + System.setProperty("aai.service.name", ResourcesApp.class.getSimpleName()); if (System.getProperty("AJSC_HOME") == null) { System.setProperty("AJSC_HOME", "."); @@ -203,7 +204,7 @@ public class ResourcesApp { } } } - private static AAIException schemaServiceExceptionTranslator(Exception ex) { + public static AAIException schemaServiceExceptionTranslator(Exception ex) { AAIException aai = null; if(ExceptionUtils.getRootCause(ex).getMessage().contains("NodeIngestor")){ aai = new AAIException("AAI_3026","Error reading OXM from SchemaService - Investigate"); diff --git a/aai-resources/src/main/resources/etc/appprops/aaiconfig.properties b/aai-resources/src/main/resources/etc/appprops/aaiconfig.properties index 6f68c41..d1aace6 100644 --- a/aai-resources/src/main/resources/etc/appprops/aaiconfig.properties +++ b/aai-resources/src/main/resources/etc/appprops/aaiconfig.properties @@ -114,4 +114,12 @@ aai.resourceversion.disabled.uuid=ajifsjisajfiasjf-oijfadao-43jj-a508-8539cd36ec aai.use.realtime=true # Threshold for margin of error (in ms) for resources_with_sot format to derive the most recent http method performed -aai.resource.formatter.threshold=10 \ No newline at end of file +aai.resource.formatter.threshold=10 + +# Indicating whether or not to log the implicit delete objects +# Set this property to true if you want to log implicit delete objects +aai.implied.delete.log.enabled=true +# Specifies how much upper bound the deletable objects should you log +# If this property is not specified it will log everything +# Uncomment it and specify an upper limit if you only want to log up to a certain deletes +#aai.implied.delete.log.limit=10000 diff --git a/aai-resources/src/main/resources/logback.xml b/aai-resources/src/main/resources/logback.xml index c903175..cb2f7e9 100644 --- a/aai-resources/src/main/resources/logback.xml +++ b/aai-resources/src/main/resources/logback.xml @@ -34,7 +34,6 @@ - @@ -250,106 +249,36 @@ ${eelfLogPattern} - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - ${logDirectory}/perf-audit/Audit-${lrmRVer}-${lrmRO}-${Pid}.log - - - ${logDirectory}/perf-audit/Audit-${lrmRVer}-${lrmRO}-${Pid}.%i.log.zip - - 1 - 9 - - - 5MB - - - "%d [%thread] %-5level %logger{1024} - %msg%n" - - - - - ${logDirectory}/perf-audit/Perform-${lrmRVer}-${lrmRO}-${Pid}.log - - - ${logDirectory}/perf-audit/Perform-${lrmRVer}-${lrmRO}-${Pid}.%i.log.zip - - 1 - 9 - - - 5MB - - - "%d [%thread] %-5level %logger{1024} - %msg%n" - - - - - - - - - - + + + + + + - - + @@ -371,11 +300,6 @@ - - - - - @@ -387,5 +311,6 @@ + diff --git a/aai-resources/src/test/java/org/onap/aai/ResourcesTestConfiguration.java b/aai-resources/src/test/java/org/onap/aai/ResourcesTestConfiguration.java index 77f82db..8ec82ff 100644 --- a/aai-resources/src/test/java/org/onap/aai/ResourcesTestConfiguration.java +++ b/aai-resources/src/test/java/org/onap/aai/ResourcesTestConfiguration.java @@ -58,31 +58,35 @@ public class ResourcesTestConfiguration { @Bean RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception { - char[] trustStorePassword = env.getProperty("server.ssl.trust-store-password").toCharArray(); - char[] keyStorePassword = env.getProperty("server.ssl.key-store-password").toCharArray(); - String keyStore = env.getProperty("server.ssl.key-store"); - String trustStore = env.getProperty("server.ssl.trust-store"); + RestTemplate restTemplate = null; + if(env.acceptsProfiles("one-way-ssl", "two-way-ssl")) { + char[] trustStorePassword = env.getProperty("server.ssl.trust-store-password").toCharArray(); + char[] keyStorePassword = env.getProperty("server.ssl.key-store-password").toCharArray(); - SSLContextBuilder sslContextBuilder = SSLContextBuilder.create(); + String keyStore = env.getProperty("server.ssl.key-store"); + String trustStore = env.getProperty("server.ssl.trust-store"); + SSLContextBuilder sslContextBuilder = SSLContextBuilder.create(); - if(env.acceptsProfiles("two-way-ssl")){ - sslContextBuilder = sslContextBuilder.loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword); - } - - SSLContext sslContext = sslContextBuilder - .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword) - .build(); + if (env.acceptsProfiles("two-way-ssl")) { + sslContextBuilder = sslContextBuilder.loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword); + } - HttpClient client = HttpClients.custom() - .setSSLContext(sslContext) - .setSSLHostnameVerifier((s, sslSession) -> true) - .build(); + SSLContext sslContext = sslContextBuilder + .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword) + .build(); - RestTemplate restTemplate = builder - .requestFactory(new HttpComponentsClientHttpRequestFactory(client)) - .build(); + HttpClient client = HttpClients.custom() + .setSSLContext(sslContext) + .setSSLHostnameVerifier((s, sslSession) -> true) + .build(); + restTemplate = builder + .requestFactory(new HttpComponentsClientHttpRequestFactory(client)) + .build(); + }else { + restTemplate = builder.build(); + } restTemplate.setErrorHandler(new ResponseErrorHandler() { @Override public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException { diff --git a/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java b/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java index ab9fdd1..c755838 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java @@ -98,7 +98,7 @@ public abstract class AbstractSpringRestTest { headers.add("Authorization", "Basic " + authorization); httpEntity = new HttpEntity(headers); - baseUrl = "https://localhost:" + randomPort; + baseUrl = "http://localhost:" + randomPort; } @After diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java index f030f20..0e1cbe4 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java @@ -78,7 +78,7 @@ public class ConfigurationTest extends AbstractSpringRestTest { headers.add("Authorization", "Basic " + authorization); httpEntity = new HttpEntity(headers); - baseUrl = "https://localhost:" + randomPort; + baseUrl = "http://localhost:" + randomPort; } @Test diff --git a/aai-resources/src/test/java/org/onap/aai/rest/CustomerFilterSearchTest.java b/aai-resources/src/test/java/org/onap/aai/rest/CustomerFilterSearchTest.java index f22c915..a52d774 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/CustomerFilterSearchTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/CustomerFilterSearchTest.java @@ -49,7 +49,7 @@ public class CustomerFilterSearchTest extends AbstractSpringRestTest { String body = PayloadUtil.getResourcePayload("customer.json"); httpEntity = new HttpEntity(body, headers); - baseUrl = "https://localhost:" + randomPort; + baseUrl = "http://localhost:" + randomPort; ResponseEntity responseEntity; responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/PserverMissingTest.java b/aai-resources/src/test/java/org/onap/aai/rest/PserverMissingTest.java index da982a9..511cf84 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/PserverMissingTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/PserverMissingTest.java @@ -50,7 +50,7 @@ public class PserverMissingTest extends AbstractSpringRestTest { String body = PayloadUtil.getTemplatePayload("pserver.json", templateMap); httpEntity = new HttpEntity(body, headers); - baseUrl = "https://localhost:" + randomPort; + baseUrl = "http://localhost:" + randomPort; ResponseEntity responseEntity; responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); @@ -72,7 +72,7 @@ public class PserverMissingTest extends AbstractSpringRestTest { headers.add("Authorization", "Basic " + authorization); httpEntity = new HttpEntity(headers); - baseUrl = "https://localhost:" + randomPort; + baseUrl = "http://localhost:" + randomPort; ResponseEntity responseEntity; responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); diff --git a/aai-resources/src/test/resources/application-test.properties b/aai-resources/src/test/resources/application-test.properties index 55717b9..320b8e1 100644 --- a/aai-resources/src/test/resources/application-test.properties +++ b/aai-resources/src/test/resources/application-test.properties @@ -13,7 +13,7 @@ spring.jersey.application-path=${schema.uri.base.path} spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration -spring.profiles.active=production,one-way-ssl +spring.profiles.active=production #The max number of active threads in this pool server.tomcat.max-threads=200 #The minimum number of threads always kept alive @@ -25,13 +25,15 @@ server.local.startpath=src/main/resources/ server.basic.auth.location=${server.local.startpath}etc/auth/realm.properties server.port=8447 -server.ssl.enabled-protocols=TLSv1.1,TLSv1.2 -server.ssl.key-store=${server.local.startpath}etc/auth/aai_keystore -server.ssl.key-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) -server.ssl.trust-store=${server.local.startpath}etc/auth/aai_keystore -server.ssl.trust-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) -server.ssl.client-auth=want -server.ssl.key-store-type=JKS +security.require-ssl=false +server.ssl.enabled=false +#server.ssl.enabled-protocols=TLSv1.1,TLSv1.2 +#server.ssl.key-store=${server.local.startpath}etc/auth/aai_keystore +#server.ssl.key-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) +#server.ssl.trust-store=${server.local.startpath}etc/auth/aai_keystore +#server.ssl.trust-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) +#server.ssl.client-auth=want +#server.ssl.key-store-type=JKS # JMS bind address host port jms.bind.address=tcp://localhost:61647 -- cgit 1.2.3-korg