diff options
Diffstat (limited to 'src/main/java/com/att/nsa/mr/tools')
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/ApiKeyCommand.java | 141 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/AuthCommand.java | 69 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/ClusterCommand.java | 80 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/MRCommandContext.java | 100 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/MRTool.java | 49 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/MessageCommand.java | 131 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/ToolsUtil.java | 40 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/TopicCommand.java | 221 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/TraceCommand.java | 118 | ||||
-rw-r--r-- | src/main/java/com/att/nsa/mr/tools/ValidatorUtil.java | 174 |
10 files changed, 0 insertions, 1123 deletions
diff --git a/src/main/java/com/att/nsa/mr/tools/ApiKeyCommand.java b/src/main/java/com/att/nsa/mr/tools/ApiKeyCommand.java deleted file mode 100644 index df28fc0..0000000 --- a/src/main/java/com/att/nsa/mr/tools/ApiKeyCommand.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.io.IOException; -import java.io.PrintStream; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.att.nsa.apiClient.credentials.ApiCredential; -import com.att.nsa.apiClient.http.HttpException; -import com.att.nsa.apiClient.http.HttpObjectNotFoundException; -import com.att.nsa.cmdtool.Command; -import com.att.nsa.cmdtool.CommandNotReadyException; -import com.att.nsa.mr.client.MRClientFactory; -import com.att.nsa.mr.client.MRIdentityManager; -import com.att.nsa.mr.client.MRClient.MRApiException; -import com.att.nsa.mr.client.MRIdentityManager.ApiKey; - -public class ApiKeyCommand implements Command<MRCommandContext> -{ - final Logger log = LoggerFactory.getLogger(ApiKeyCommand.class); - @Override - public String[] getMatches () - { - return new String[]{ - "key (create|update) (\\S*) (\\S*)", - "key (list) (\\S*)", - "key (revoke)", - }; - } - - @Override - public void checkReady ( MRCommandContext context ) throws CommandNotReadyException - { - if ( !context.checkClusterReady () ) - { - throw new CommandNotReadyException ( "Use 'cluster' to specify a cluster to use." ); - } - } - - @Override - public void execute ( String[] parts, MRCommandContext context, PrintStream out ) throws CommandNotReadyException - { - final MRIdentityManager tm = MRClientFactory.createIdentityManager ( context.getCluster(), context.getApiKey(), context.getApiPwd() ); - context.applyTracer ( tm ); - - try - { - if ( parts[0].equals ( "list" ) ) - { - final ApiKey key = tm.getApiKey ( parts[1] ); - if ( key != null ) - { - out.println ( "email: " + key.getEmail () ); - out.println ( "description: " + key.getDescription () ); - } - else - { - out.println ( "No key returned" ); - } - } - else if ( parts[0].equals ( "create" ) ) - { - final ApiCredential ac = tm.createApiKey ( parts[1], parts[2] ); - if ( ac != null ) - { - out.println ( " key: " + ac.getApiKey () ); - out.println ( "secret: " + ac.getApiSecret () ); - } - else - { - out.println ( "No credential returned?" ); - } - } - else if ( parts[0].equals ( "update" ) ) - { - tm.updateCurrentApiKey ( parts[1], parts[2] ); - out.println ( "Updated" ); - } - else if ( parts[0].equals ( "revoke" ) ) - { - tm.deleteCurrentApiKey (); - out.println ( "Updated" ); - } - } - catch ( HttpObjectNotFoundException e ) - { - out.println ( "Object not found: " + e.getMessage () ); - log.error("HttpObjectNotFoundException: ", e); - } - catch ( HttpException e ) - { - out.println ( "HTTP exception: " + e.getMessage () ); - log.error("HttpException: ", e); - } - catch ( MRApiException e ) - { - out.println ( "API exception: " + e.getMessage () ); - log.error("MRApiException: ", e); - } - catch ( IOException e ) - { - out.println ( "IO exception: " + e.getMessage () ); - log.error("IOException: ", e); - } - finally - { - tm.close (); - } - } - - @Override - public void displayHelp ( PrintStream out ) - { - out.println ( "key create <email> <description>" ); - out.println ( "key update <email> <description>" ); - out.println ( "key list <key>" ); - out.println ( "key revoke" ); - } -} diff --git a/src/main/java/com/att/nsa/mr/tools/AuthCommand.java b/src/main/java/com/att/nsa/mr/tools/AuthCommand.java deleted file mode 100644 index 72f226b..0000000 --- a/src/main/java/com/att/nsa/mr/tools/AuthCommand.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.io.PrintStream; - -import com.att.nsa.cmdtool.Command; -import com.att.nsa.cmdtool.CommandNotReadyException; - -public class AuthCommand implements Command<MRCommandContext> -{ - @Override - public void checkReady ( MRCommandContext context ) throws CommandNotReadyException - { - } - - @Override - public void execute ( String[] parts, MRCommandContext context, PrintStream out ) throws CommandNotReadyException - { - if ( parts.length > 0 ) - { - context.setAuth ( parts[0], parts[1] ); - out.println ( "Now authenticating with " + parts[0] ); - } - else - { - context.clearAuth (); - out.println ( "No longer authenticating." ); - } - } - - @Override - public void displayHelp ( PrintStream out ) - { - out.println ( "auth <apiKey> <apiSecret>" ); - out.println ( "\tuse these credentials on subsequent transactions" ); - out.println ( "noauth" ); - out.println ( "\tdo not use credentials on subsequent transactions" ); - } - - @Override - public String[] getMatches () - { - return new String[] - { - "auth (\\S*) (\\S*)", - "noauth" - }; - } -} diff --git a/src/main/java/com/att/nsa/mr/tools/ClusterCommand.java b/src/main/java/com/att/nsa/mr/tools/ClusterCommand.java deleted file mode 100644 index 5ecaf7c..0000000 --- a/src/main/java/com/att/nsa/mr/tools/ClusterCommand.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.io.PrintStream; - -import com.att.nsa.cmdtool.Command; -import com.att.nsa.cmdtool.CommandNotReadyException; -import com.att.nsa.mr.client.impl.MRConsumerImpl; - -public class ClusterCommand implements Command<MRCommandContext> -{ - - @Override - public String[] getMatches () - { - return new String[]{ - "cluster", - "cluster (\\S*)?", - }; - } - - @Override - public void checkReady ( MRCommandContext context ) throws CommandNotReadyException - { - } - - @Override - public void execute ( String[] parts, MRCommandContext context, PrintStream out ) throws CommandNotReadyException - { - if ( parts.length == 0 ) - { - for ( String host : context.getCluster () ) - { - out.println ( host ); - } - } - else - { - context.clearCluster (); - for ( String part : parts ) - { - String[] hosts = part.trim().split ( "\\s+" ); - for ( String host : hosts ) - { - for ( String splitHost : MRConsumerImpl.stringToList(host) ) - { - context.addClusterHost ( splitHost ); - } - } - } - } - } - - @Override - public void displayHelp ( PrintStream out ) - { - out.println ( "cluster host1 host2 ..." ); - } - -} diff --git a/src/main/java/com/att/nsa/mr/tools/MRCommandContext.java b/src/main/java/com/att/nsa/mr/tools/MRCommandContext.java deleted file mode 100644 index e512769..0000000 --- a/src/main/java/com/att/nsa/mr/tools/MRCommandContext.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.util.Collection; -import java.util.LinkedList; - -import com.att.nsa.apiClient.http.HttpClient; -import com.att.nsa.apiClient.http.HttpTracer; -import com.att.nsa.cmdtool.CommandContext; -import com.att.nsa.mr.client.MRClient; - -public class MRCommandContext implements CommandContext -{ - public MRCommandContext () - { - fApiKey = null; - fApiPwd = null; - - fCluster = new LinkedList<> (); - fCluster.add ( "localhost" ); - } - - @Override - public void requestShutdown () - { - fShutdown = true; - } - - @Override - public boolean shouldContinue () - { - return !fShutdown; - } - - public void setAuth ( String key, String pwd ) { fApiKey = key; fApiPwd = pwd; } - public void clearAuth () { setAuth(null,null); } - - public boolean checkClusterReady () - { - return ( fCluster.isEmpty()); - } - - public Collection<String> getCluster () - { - return new LinkedList<> ( fCluster ); - } - - public void clearCluster () - { - fCluster.clear (); - } - - public void addClusterHost ( String host ) - { - fCluster.add ( host ); - } - - public String getApiKey () { return fApiKey; } - public String getApiPwd () { return fApiPwd; } - - public void useTracer ( HttpTracer t ) - { - fTracer = t; - } - public void noTracer () { fTracer = null; } - - public void applyTracer ( MRClient cc ) - { - if ( cc instanceof HttpClient && fTracer != null ) - { - ((HttpClient)cc).installTracer ( fTracer ); - } - } - - private boolean fShutdown; - private String fApiKey; - private String fApiPwd; - private final LinkedList<String> fCluster; - private HttpTracer fTracer = null; -} diff --git a/src/main/java/com/att/nsa/mr/tools/MRTool.java b/src/main/java/com/att/nsa/mr/tools/MRTool.java deleted file mode 100644 index 7f1effd..0000000 --- a/src/main/java/com/att/nsa/mr/tools/MRTool.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.io.IOException; - -import com.att.nsa.cmdtool.CommandLineTool; -import com.att.nsa.mr.client.impl.MRClientVersionInfo; - -public class MRTool extends CommandLineTool<MRCommandContext> -{ - protected MRTool () - { - super ( "MR Tool (" + MRClientVersionInfo.getVersion () + ")", "MR> " ); - - registerCommand ( new ApiKeyCommand () ); - registerCommand ( new AuthCommand () ); - registerCommand ( new ClusterCommand () ); - registerCommand ( new MessageCommand () ); - registerCommand ( new TopicCommand () ); - registerCommand ( new TraceCommand () ); - } - - public static void main ( String[] args ) throws IOException - { - final MRTool ct = new MRTool (); - final MRCommandContext ccc = new MRCommandContext (); - ct.runFromMain ( args, ccc ); - } -} diff --git a/src/main/java/com/att/nsa/mr/tools/MessageCommand.java b/src/main/java/com/att/nsa/mr/tools/MessageCommand.java deleted file mode 100644 index 54e92ae..0000000 --- a/src/main/java/com/att/nsa/mr/tools/MessageCommand.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.att.nsa.cmdtool.Command; -import com.att.nsa.cmdtool.CommandNotReadyException; -import com.att.nsa.mr.client.MRBatchingPublisher; -import com.att.nsa.mr.client.MRClientFactory; -import com.att.nsa.mr.client.MRConsumer; -import com.att.nsa.mr.client.MRClientBuilders.PublisherBuilder; -import com.att.nsa.mr.client.MRPublisher.message; - -public class MessageCommand implements Command<MRCommandContext> -{ - final Logger logger = LoggerFactory.getLogger(ApiKeyCommand.class); - @Override - public String[] getMatches () - { - return new String[]{ - "(post) (\\S*) (\\S*) (.*)", - "(read) (\\S*) (\\S*) (\\S*)", - }; - } - - @Override - public void checkReady ( MRCommandContext context ) throws CommandNotReadyException - { - if ( !context.checkClusterReady () ) - { - throw new CommandNotReadyException ( "Use 'cluster' to specify a cluster to use." ); - } - } - - @Override - public void execute ( String[] parts, MRCommandContext context, PrintStream out ) throws CommandNotReadyException - { - if ( parts[0].equalsIgnoreCase ( "read" )) - { - final MRConsumer cc = MRClientFactory.createConsumer ( context.getCluster (), parts[1], parts[2], parts[3], - -1, -1, null, context.getApiKey(), context.getApiPwd() ); - context.applyTracer ( cc ); - try - { - for ( String msg : cc.fetch () ) - { - out.println ( msg ); - } - } - catch ( Exception e ) - { - out.println ( "Problem fetching messages: " + e.getMessage() ); - logger.error("Problem fetching messages: ", e); - } - finally - { - cc.close (); - } - } - else - { - final MRBatchingPublisher pub=ToolsUtil.createBatchPublisher(context, parts[1]); - try - { - pub.send ( parts[2], parts[3] ); - } - catch ( IOException e ) - { - out.println ( "Problem sending message: " + e.getMessage() ); - logger.error("Problem sending message: ", e); - } - finally - { - List<message> left = null; - try - { - left = pub.close ( 500, TimeUnit.MILLISECONDS ); - } - catch ( IOException e ) - { - out.println ( "Problem sending message: " + e.getMessage() ); - logger.error("Problem sending message: ", e); - } - catch ( InterruptedException e ) - { - out.println ( "Problem sending message: " + e.getMessage() ); - logger.error("Problem sending message: ", e); - Thread.currentThread().interrupt(); - } - if ( left != null && left.isEmpty() ) - { - out.println ( left.size() + " messages not sent." ); - } - } - } - } - - @Override - public void displayHelp ( PrintStream out ) - { - out.println ( "post <topicName> <partition> <message>" ); - out.println ( "read <topicName> <consumerGroup> <consumerId>" ); - } - -} diff --git a/src/main/java/com/att/nsa/mr/tools/ToolsUtil.java b/src/main/java/com/att/nsa/mr/tools/ToolsUtil.java deleted file mode 100644 index 45b21d1..0000000 --- a/src/main/java/com/att/nsa/mr/tools/ToolsUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * 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 com.att.nsa.mr.tools; - -import com.att.nsa.mr.client.MRBatchingPublisher; -import com.att.nsa.mr.client.MRClientBuilders.PublisherBuilder; - -public final class ToolsUtil { - - private ToolsUtil() { - } - - public static MRBatchingPublisher createBatchPublisher(MRCommandContext context,String topicName){ - - return new PublisherBuilder (). - usingHosts ( context.getCluster () ). - onTopic (topicName). - authenticatedBy ( context.getApiKey(), context.getApiPwd() ). - build (); - } - -} diff --git a/src/main/java/com/att/nsa/mr/tools/TopicCommand.java b/src/main/java/com/att/nsa/mr/tools/TopicCommand.java deleted file mode 100644 index 4b1151e..0000000 --- a/src/main/java/com/att/nsa/mr/tools/TopicCommand.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.att.nsa.apiClient.http.HttpException; -import com.att.nsa.apiClient.http.HttpObjectNotFoundException; -import com.att.nsa.cmdtool.Command; -import com.att.nsa.cmdtool.CommandNotReadyException; -import com.att.nsa.mr.client.MRClientFactory; -import com.att.nsa.mr.client.MRTopicManager; -import com.att.nsa.mr.client.MRTopicManager.TopicInfo; - -public class TopicCommand implements Command<MRCommandContext> -{ - final Logger logger = LoggerFactory.getLogger(ApiKeyCommand.class); - @Override - public String[] getMatches () - { - return new String[]{ - "topic (list)", - "topic (list) (\\S*)", - "topic (create) (\\S*) (\\S*) (\\S*)", - "topic (grant|revoke) (read|write) (\\S*) (\\S*)", - }; - } - - @Override - public void checkReady ( MRCommandContext context ) throws CommandNotReadyException - { - if ( !context.checkClusterReady () ) - { - throw new CommandNotReadyException ( "Use 'cluster' to specify a cluster to use." ); - } - } - - @Override - public void execute ( String[] parts, MRCommandContext context, PrintStream out ) throws CommandNotReadyException - { - final MRTopicManager tm = MRClientFactory.createTopicManager ( context.getCluster(), context.getApiKey(), context.getApiPwd() ); - context.applyTracer ( tm ); - - try - { - if ( parts[0].equals ( "list" ) ) - { - try - { - if ( parts.length == 1 ) - { - for ( String topic : tm.getTopics () ) - { - out.println ( topic ); - } - } - else - { - final TopicInfo ti = tm.getTopicMetadata ( parts[1] ); - - final String owner = ti.getOwner (); - out.println ( " owner: " + ( owner == null ? "<none>" : owner ) ); - - final String desc = ti.getDescription (); - out.println ( "description: " + ( desc == null ? "<none>" : desc ) ); - - final Set<String> prods = ti.getAllowedProducers (); - if ( prods != null ) - { - out.println ( " write ACL: " ); - for ( String key : prods ) - { - out.println ( "\t" + key ); - } - } - else - { - out.println ( " write ACL: <not active>" ); - } - - final Set<String> cons = ti.getAllowedConsumers (); - if ( cons != null ) - { - out.println ( " read ACL: " ); - for ( String key : cons ) - { - out.println ( "\t" + key ); - } - } - else - { - out.println ( " read ACL: <not active>" ); - } - } - } - catch ( IOException x ) - { - out.println ( "Problem with request: " + x.getMessage () ); - logger.error("IOException: ", x); - } - catch ( HttpObjectNotFoundException e ) - { - out.println ( "Not found: " + e.getMessage () ); - logger.error("HttpObjectNotFoundException: ", e); - } - } - else if ( parts[0].equals ( "create" ) ) - { - try - { - final int partitions = Integer.parseInt ( parts[2] ); - final int replicas = Integer.parseInt ( parts[3] ); - - tm.createTopic ( parts[1], "", partitions, replicas ); - } - catch ( HttpException e ) - { - out.println ( "Problem with request: " + e.getMessage () ); - logger.error("HttpException: ", e); - } - catch ( IOException e ) - { - out.println ( "Problem with request: " + e.getMessage () ); - logger.error("IOException: ", e); - } - catch ( NumberFormatException e ) - { - out.println ( "Problem with request: " + e.getMessage () ); - logger.error("NumberFormatException: ", e); - } - } - else if ( parts[0].equals ( "grant" ) ) - { - try - { - if ( parts[1].equals ( "write" ) ) - { - tm.allowProducer ( parts[2], parts[3] ); - } - else if ( parts[1].equals ( "read" ) ) - { - tm.allowConsumer ( parts[2], parts[3] ); - } - } - catch ( HttpException e ) - { - out.println ( "Problem with request: " + e.getMessage () ); - logger.error("HttpException: ", e); - } - catch ( IOException e ) - { - out.println ( "Problem with request: " + e.getMessage () ); - logger.error("IOException: ", e); - } - } - else if ( parts[0].equals ( "revoke" ) ) - { - try - { - if ( parts[1].equals ( "write" ) ) - { - tm.revokeProducer ( parts[2], parts[3] ); - } - else if ( parts[1].equals ( "read" ) ) - { - tm.revokeConsumer ( parts[2], parts[3] ); - } - } - catch ( HttpException e ) - { - out.println ( "Problem with request: " + e.getMessage () ); - logger.error("HttpException: ", e); - } - catch ( IOException e ) - { - out.println ( "Problem with request: " + e.getMessage () ); - logger.error("IOException: ", e); - } - } - } - finally - { - tm.close (); - } - } - - @Override - public void displayHelp ( PrintStream out ) - { - out.println ( "topic list" ); - out.println ( "topic list <topicName>" ); - out.println ( "topic create <topicName> <partitions> <replicas>" ); - out.println ( "topic grant write|read <topicName> <apiKey>" ); - out.println ( "topic revoke write|read <topicName> <apiKey>" ); - } - -} diff --git a/src/main/java/com/att/nsa/mr/tools/TraceCommand.java b/src/main/java/com/att/nsa/mr/tools/TraceCommand.java deleted file mode 100644 index 0489172..0000000 --- a/src/main/java/com/att/nsa/mr/tools/TraceCommand.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.io.PrintStream; -import java.net.URI; -import java.util.List; -import java.util.Map; - -import com.att.nsa.apiClient.http.HttpTracer; -import com.att.nsa.cmdtool.Command; -import com.att.nsa.cmdtool.CommandNotReadyException; - -public class TraceCommand implements Command<MRCommandContext> -{ - @Override - public void checkReady ( MRCommandContext context ) throws CommandNotReadyException - { - } - - @Override - public void execute ( String[] parts, MRCommandContext context, final PrintStream out ) throws CommandNotReadyException - { - if ( parts[0].equalsIgnoreCase ( "on" )) - { - context.useTracer ( new HttpTracer () - { - @Override - public void outbound ( URI uri, Map<String, List<String>> headers, String method, byte[] entity ) - { - out.println ( kLineBreak ); - out.println ( ">>> " + method + " " + uri.toString() ); - for ( Map.Entry<String,List<String>> e : headers.entrySet () ) - { - final StringBuffer vals = new StringBuffer (); - for ( String val : e.getValue () ) - { - if ( vals.length () > 0 ) vals.append ( ", " ); - vals.append ( val ); - } - out.println ( ">>> " + e.getKey () + ": " + vals.toString() ); - } - if ( entity != null ) - { - out.println (); - out.println ( new String ( entity ) ); - } - out.println ( kLineBreak ); - } - - @Override - public void inbound ( Map<String, List<String>> headers, int statusCode, String responseLine, byte[] entity ) - { - out.println ( kLineBreak ); - out.println ( "<<< " + responseLine ); - for ( Map.Entry<String,List<String>> e : headers.entrySet () ) - { - final StringBuffer vals = new StringBuffer (); - for ( String val : e.getValue () ) - { - if ( vals.length () > 0 ) vals.append ( ", " ); - vals.append ( val ); - } - out.println ( "<<< " + e.getKey () + ": " + vals.toString() ); - } - if ( entity != null ) - { - out.println (); - out.println ( new String ( entity ) ); - } - out.println ( kLineBreak ); - } - } ); - } - else - { - context.noTracer (); - } - } - - @Override - public void displayHelp ( PrintStream out ) - { - out.println ( "trace on|off" ); - out.println ( "\tWhen trace is on, HTTP interaction is printed to the console." ); - } - - @Override - public String[] getMatches () - { - return new String[] - { - "trace (on)", - "trace (off)" - }; - } - - private static final String kLineBreak = "======================================================================"; -} diff --git a/src/main/java/com/att/nsa/mr/tools/ValidatorUtil.java b/src/main/java/com/att/nsa/mr/tools/ValidatorUtil.java deleted file mode 100644 index 0539582..0000000 --- a/src/main/java/com/att/nsa/mr/tools/ValidatorUtil.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * org.onap.dmaap - * ================================================================================ - * Copyright © 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 is a trademark and service mark of AT&T Intellectual Property. - * - *******************************************************************************/ -package com.att.nsa.mr.tools; - -import java.util.Properties; - -import com.att.nsa.mr.test.clients.ProtocolTypeConstants; - -public class ValidatorUtil { - - public static void validatePublisher(Properties props) { - String transportType = props.getProperty("TransportType"); - if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(transportType)) { - validateForDME2(props); - } else { - validateForNonDME2(props); - } - String maxBatchSize = props.getProperty("maxBatchSize"); - if (maxBatchSize == null || maxBatchSize.isEmpty()) { - throw new IllegalArgumentException ( "maxBatchSize is needed" ); - } - String maxAgeMs = props.getProperty("maxAgeMs"); - if (maxAgeMs == null || maxAgeMs.isEmpty()) { - throw new IllegalArgumentException ( "maxAgeMs is needed" ); - } - String messageSentThreadOccurance = props.getProperty("MessageSentThreadOccurance"); - if (messageSentThreadOccurance == null || messageSentThreadOccurance.isEmpty()) { - throw new IllegalArgumentException ( "MessageSentThreadOccurance is needed" ); - } - - } - - public static void validateSubscriber(Properties props) { - String transportType = props.getProperty("TransportType"); - if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(transportType)) { - validateForDME2(props); - } else { - validateForNonDME2(props); - } - String group = props.getProperty("group"); - if (group == null || group.isEmpty()) { - throw new IllegalArgumentException ( "group is needed" ); - } - String id = props.getProperty("id"); - if (id == null || id.isEmpty()) { - throw new IllegalArgumentException ( "Consumer (Id) is needed" ); - } - } - - private static void validateForDME2(Properties props) { - String serviceName = props.getProperty("ServiceName"); - if (serviceName == null || serviceName.isEmpty()) { - throw new IllegalArgumentException ( "Servicename is needed" ); - } - String topic = props.getProperty("topic"); - if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException ( "topic is needed" ); - } - String username = props.getProperty("username"); - if (username == null || username.isEmpty()) { - throw new IllegalArgumentException ( "username is needed" ); - } - String password = props.getProperty("password"); - if (password == null || password.isEmpty()) { - throw new IllegalArgumentException ( "password is needed" ); - } - String dME2preferredRouterFilePath = props.getProperty("DME2preferredRouterFilePath"); - if (dME2preferredRouterFilePath == null || dME2preferredRouterFilePath.isEmpty()) { - throw new IllegalArgumentException ( "DME2preferredRouterFilePath is needed" ); - } - String partner = props.getProperty("Partner"); - String routeOffer = props.getProperty("routeOffer"); - if ((partner == null || partner.isEmpty()) && (routeOffer == null || routeOffer.isEmpty())) { - throw new IllegalArgumentException ( "Partner or routeOffer is needed" ); - } - String protocol = props.getProperty("Protocol"); - if (protocol == null || protocol.isEmpty()) { - throw new IllegalArgumentException ( "Protocol is needed" ); - } - String methodType = props.getProperty("MethodType"); - if (methodType == null || methodType.isEmpty()) { - throw new IllegalArgumentException ( "MethodType is needed" ); - } - String contenttype = props.getProperty("contenttype"); - if (contenttype == null || contenttype.isEmpty()) { - throw new IllegalArgumentException ( "contenttype is needed" ); - } - String latitude = props.getProperty("Latitude"); - if (latitude == null || latitude.isEmpty()) { - throw new IllegalArgumentException ( "Latitude is needed" ); - } - String longitude = props.getProperty("Longitude"); - if (longitude == null || longitude.isEmpty()) { - throw new IllegalArgumentException ( "Longitude is needed" ); - } - String aftEnv = props.getProperty("AFT_ENVIRONMENT"); - if (aftEnv == null || aftEnv.isEmpty()) { - throw new IllegalArgumentException ( "AFT_ENVIRONMENT is needed" ); - } - String version = props.getProperty("Version"); - if (version == null || version.isEmpty()) { - throw new IllegalArgumentException ( "Version is needed" ); - } - String environment = props.getProperty("Environment"); - if (environment == null || environment.isEmpty()) { - throw new IllegalArgumentException ( "Environment is needed" ); - } - String subContextPath = props.getProperty("SubContextPath"); - if (subContextPath == null || subContextPath.isEmpty()) { - throw new IllegalArgumentException ( "SubContextPath is needed" ); - } - String sessionstickinessrequired = props.getProperty("sessionstickinessrequired"); - if (sessionstickinessrequired == null || sessionstickinessrequired.isEmpty()) { - throw new IllegalArgumentException ( "sessionstickinessrequired is needed" ); - } - } - - private static void validateForNonDME2(Properties props) { - String transportType = props.getProperty("TransportType"); - String host = props.getProperty("host"); - if (host == null || host.isEmpty()) { - throw new IllegalArgumentException ( "Servicename is needed" ); - } - String topic = props.getProperty("topic"); - if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException ( "topic is needed" ); - } - String contenttype = props.getProperty("contenttype"); - if (contenttype == null || contenttype.isEmpty()) { - throw new IllegalArgumentException ( "contenttype is needed" ); - } - if (!ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(transportType)){ - String username = props.getProperty("username"); - if (username == null || username.isEmpty()) { - throw new IllegalArgumentException ( "username is needed" ); - } - String password = props.getProperty("password"); - if (password == null || password.isEmpty()) { - throw new IllegalArgumentException ( "password is needed" ); - } - } - if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(transportType)) { - String authKey = props.getProperty("authKey"); - if (authKey == null || authKey.isEmpty()) { - throw new IllegalArgumentException ( "authKey is needed" ); - } - String authDate = props.getProperty("authDate"); - if (authDate == null || authDate.isEmpty()) { - throw new IllegalArgumentException ( "authDate is needed" ); - } - - } - } - -} |