From 12414fe43077e12d7ef711951b1633ad31d73573 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Tue, 22 Jan 2019 10:27:32 -0600 Subject: Public and Private Locate entries Issue-ID: AAF-723 Change-Id: I9dcd2e732ce64b39aaa57a6e9404f275f7ad540c Signed-off-by: Instrumental --- auth/auth-core/pom.xml | 2 +- .../main/java/org/onap/aaf/auth/env/AuthzEnv.java | 5 +- .../main/java/org/onap/aaf/auth/layer/Result.java | 2 - .../java/org/onap/aaf/auth/server/AbsService.java | 54 +++++++++--------- .../onap/aaf/auth/server/AbsServiceStarter.java | 46 ++++++++++++--- .../onap/aaf/auth/server/JettyServiceStarter.java | 30 +++------- .../org/onap/aaf/auth/server/ServiceStarter.java | 2 +- .../java/org/onap/aaf/auth/server/TestKill.java | 65 ++++++++++++++++++++++ .../onap/aaf/auth/server/test/JU_AbsService.java | 3 +- .../aaf/auth/server/test/JU_AbsServiceStarter.java | 3 +- 10 files changed, 147 insertions(+), 65 deletions(-) create mode 100644 auth/auth-core/src/main/java/org/onap/aaf/auth/server/TestKill.java (limited to 'auth/auth-core') diff --git a/auth/auth-core/pom.xml b/auth/auth-core/pom.xml index 96153818..a4b01cd9 100644 --- a/auth/auth-core/pom.xml +++ b/auth/auth-core/pom.xml @@ -25,7 +25,7 @@ org.onap.aaf.authz authparent - 2.1.9-SNAPSHOT + 2.1.10-SNAPSHOT ../pom.xml diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java index 56db6f60..497c13d6 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java @@ -102,7 +102,10 @@ public class AuthzEnv extends RosettaEnv implements Access { @Override public void log(Throwable e, Object... msgs) { - access.log(Level.ERROR, msgs); + Object[] nm = new Object[msgs.length+1]; + System.arraycopy(msgs, 0, nm, 1, msgs.length); + nm[0]=e; + access.log(Level.ERROR, nm); } @Override diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java index 3e68e3ab..e064ade3 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java @@ -275,8 +275,6 @@ public class Result { * @return */ public boolean isOKhasData() { - System.out.println("specialCondition:"+specialCondition); - System.out.println("specialCondition:"+(specialCondition & EMPTY_LIST)); return status == OK && (specialCondition & EMPTY_LIST) != EMPTY_LIST; } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java index 435b8845..9ece4847 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java @@ -54,42 +54,30 @@ public abstract class AbsService exte public final String app_name; public final String app_version; - public final String app_interface_version; public final String ROOT_NS; - + public AbsService(final Access access, final ENV env) throws CadiException { - Define.set(access); - ROOT_NS = Define.ROOT_NS(); + Define.set(access); + ROOT_NS = Define.ROOT_NS(); this.access = access; this.env = env; - String component = access.getProperty(Config.AAF_COMPONENT, null); - final String[] locator_deploy; - - if (component == null) { - locator_deploy = null; + String str = access.getProperty(Config.AAF_LOCATOR_NAMES, null); + String[] scomp = Split.splitTrim(',', str); + if(scomp.length==0) { + throw new CadiException(Config.AAF_LOCATOR_NAMES + " must be defined."); } else { - locator_deploy = Split.splitTrim(':', component); - if(locator_deploy.length>1 && "AAF_RELEASE".equals(locator_deploy[1])) { - locator_deploy[1]=access.getProperty(Config.AAF_RELEASE, Defaults.AAF_VERSION); - int snapshot = locator_deploy[1].indexOf("-SNAPSHOT"); - if(snapshot>0) { - locator_deploy[1]=locator_deploy[1].substring(0, snapshot); - } - } - } - - if (component == null || locator_deploy==null || locator_deploy.length<2) { - throw new CadiException("AAF Component must include the " + Config.AAF_COMPONENT + " property, : exte access.log(Level.DEBUG,sb); } } + + public void setProtocol(String proto) { + env.setProperty(Config.AAF_LOCATOR_PROTOCOL, proto); + } + public void setSubprotocol(String subproto) { + env.setProperty(Config.AAF_LOCATOR_SUBPROTOCOL, subproto); + } + protected abstract Filter[] _filters(Object ... additionalTafLurs) throws CadiException, LocatorException; /** @@ -125,7 +121,7 @@ public abstract class AbsService exte return _filters(); } - public abstract Registrant[] registrants(final int port) throws CadiException, LocatorException; + public abstract Registrant[] registrants(final int actualPort) throws CadiException, LocatorException; // Lazy Instantiation public synchronized AAFConHttp aafCon() throws CadiException, LocatorException { diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java index 29166b0b..8f0eb8aa 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java @@ -19,10 +19,17 @@ * */ package org.onap.aaf.auth.server; +import java.io.IOException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + import org.onap.aaf.auth.org.OrganizationException; import org.onap.aaf.auth.org.OrganizationFactory; import org.onap.aaf.auth.rserv.RServlet; import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.register.Registrant; import org.onap.aaf.cadi.register.Registrar; import org.onap.aaf.misc.env.Trans; @@ -61,14 +68,30 @@ public abstract class AbsServiceStarter app = es.submit(this); + final AbsServiceStarter absSS = this; + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + absSS.access().printf(Level.INIT, "Shutting down %s:%s\n",absSS.service.app_name, absSS.service.app_version); + absSS.shutdown(); + app.cancel(true); + } + }); + if(System.getProperty("ECLIPSE", null)!=null) { + Thread.sleep(2000); + System.out.println("Service Started in Eclipse: "); + System.out.print(" Hit to end:"); + try { + System.in.read(); + System.exit(0); + } catch (IOException e) { + } + } + } + @SafeVarargs public final synchronized void register(final Registrant ... registrants) { @@ -83,6 +106,15 @@ public abstract class AbsServiceStarter extends AbsServiceStarter { - private boolean secure; public JettyServiceStarter(final AbsService service) throws OrganizationException { @@ -73,24 +72,6 @@ public class JettyServiceStarter ex return this; } -// @Override -// public void _propertyAdjustment() { -// Properties props = access().getProperties(); -// Object temp = null; -// // Critical - if no Security Protocols set, then set it. We'll just get messed up if not -// if ((temp=props.get(Config.CADI_PROTOCOLS))==null) { -// if ((temp=props.get(Config.HTTPS_PROTOCOLS))==null) { -// props.put(Config.CADI_PROTOCOLS, SecurityInfo.HTTPS_PROTOCOLS_DEFAULT); -// } else { -// props.put(Config.CADI_PROTOCOLS, temp); -// } -// } -// -// if ("1.7".equals(System.getProperty("java.specification.version"))) { -// System.setProperty(Config.HTTPS_CIPHER_SUITES, Config.HTTPS_CIPHER_SUITES_DEFAULT); -// } -// System.setProperty(Config.HTTPS_CIPHER_SUITES, temp.toString()); -// } @Override public void _propertyAdjustment() { @@ -129,6 +110,7 @@ public class JettyServiceStarter ex protocol = "http"; } else { protocol = "https"; + String keystorePassword = access().getProperty(Config.CADI_KEYSTORE_PASSWORD, null); if (keystorePassword==null) { @@ -151,7 +133,9 @@ public class JettyServiceStarter ex sslContextFactory.setTrustStorePassword(access().decrypt(truststorePassword, true)); } // Be able to accept only certain protocols, i.e. TLSv1.1+ - final String[] protocols = Split.splitTrim(',', access().getProperty(Config.CADI_PROTOCOLS, SecurityInfo.HTTPS_PROTOCOLS_DEFAULT)); + String subprotocols = access().getProperty(Config.CADI_PROTOCOLS, SecurityInfo.HTTPS_PROTOCOLS_DEFAULT); + service.setSubprotocol(subprotocols); + final String[] protocols = Split.splitTrim(',', subprotocols); sslContextFactory.setIncludeProtocols(protocols); // Want to use Client Certificates, if they exist. @@ -178,6 +162,8 @@ public class JettyServiceStarter ex new HttpConnectionFactory(httpConfig) ); } + service.setProtocol(protocol); + // Setup JMX // TODO trying to figure out how to set up/log ports @@ -220,7 +206,7 @@ public class JettyServiceStarter ex server.start(); access().log(Level.INIT,server.dump()); } catch (Exception e) { - access().log(e,"Error starting " + service.app_name); + access().log(e,"Error starting " + hostname + ':' + port + ' ' + InetAddress.getLocalHost().getHostAddress()); String doExit = access().getProperty("cadi_exitOnFailure", "true"); if (doExit == "true") { System.exit(1); @@ -231,7 +217,7 @@ public class JettyServiceStarter ex try { register(service.registrants(port)); access().printf(Level.INIT, "Starting Jetty Service for %s, version %s, on %s://%s:%d", service.app_name,service.app_version,protocol,hostname,port); - server.join(); + //server.join(); } catch (Exception e) { access().log(e,"Error registering " + service.app_name); String doExit = access().getProperty("cadi_exitOnFailure", "true"); diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/ServiceStarter.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/ServiceStarter.java index 6f2d4cb9..9004f76b 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/ServiceStarter.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/ServiceStarter.java @@ -20,7 +20,7 @@ */ package org.onap.aaf.auth.server; -public interface ServiceStarter { +public interface ServiceStarter extends Runnable { public void start() throws Exception; public void shutdown(); } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/TestKill.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/TestKill.java new file mode 100644 index 00000000..78172a22 --- /dev/null +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/TestKill.java @@ -0,0 +1,65 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 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.aaf.auth.server; + +import java.io.IOException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public class TestKill implements Runnable { + + public static void main(String[] args) { + ExecutorService es = Executors.newSingleThreadExecutor(); + TestKill tk = new TestKill(); + Future app = es.submit(tk); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + System.out.println("Shutdown Hook, thread: setting interrupt"); + app.cancel(true); + tk.longProcess(); + es.shutdown(); + } + }); + System.out.println("Service Start"); + System.out.print("Hit to end:"); + try { + System.in.read(); + System.exit(0); + } catch (IOException e) { + } + } + + @Override + public void run() { + } + + private void longProcess() { + System.out.println("Starting long cleanup process"); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("Ending long cleanup process"); + } +} diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsService.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsService.java index a0ee9ef9..65f019f0 100644 --- a/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsService.java +++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsService.java @@ -103,7 +103,8 @@ public class JU_AbsService { BasicEnv bEnv = new BasicEnv(); PropAccess prop = new PropAccess(); - prop.setProperty(Config.AAF_COMPONENT, "te.st:te.st"); + prop.setProperty(Config.AAF_LOCATOR_NAMES, "te.st"); + prop.setProperty(Config.AAF_LOCATOR_VERSION, "te.st"); prop.setLogLevel(Level.DEBUG); AbsServiceStub absServiceStub = new AbsServiceStub(prop, bEnv); //Testing other branches requires "fails" due to exception handling, will leave that off for now. } diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsServiceStarter.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsServiceStarter.java index 1f5d70ae..1fe98d84 100644 --- a/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsServiceStarter.java +++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsServiceStarter.java @@ -131,7 +131,8 @@ public class JU_AbsServiceStarter { BasicEnv bEnv = new BasicEnv(); PropAccess prop = new PropAccess(); - prop.setProperty(Config.AAF_COMPONENT, "te.st:te.st"); + prop.setProperty(Config.AAF_LOCATOR_NAMES, "te.st"); + prop.setProperty(Config.AAF_LOCATOR_VERSION, "te.st"); prop.setLogLevel(Level.DEBUG); absServiceStub = new AbsServiceStub(prop, bEnv); -- cgit 1.2.3-korg