aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dmaap/mr/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/dmaap/mr/tools')
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/ApiKeyCommand.java191
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/AuthCommand.java76
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/ClusterCommand.java88
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/MRCommandContext.java151
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/MRTool.java49
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/MessageCommand.java170
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/ToolsUtil.java22
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/TopicCommand.java321
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/TraceCommand.java159
-rw-r--r--src/main/java/org/onap/dmaap/mr/tools/ValidatorUtil.java338
10 files changed, 726 insertions, 839 deletions
diff --git a/src/main/java/org/onap/dmaap/mr/tools/ApiKeyCommand.java b/src/main/java/org/onap/dmaap/mr/tools/ApiKeyCommand.java
index a2396d8..6a2bf37 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/ApiKeyCommand.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/ApiKeyCommand.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,125 +19,102 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
-package org.onap.dmaap.mr.tools;
-import java.io.IOException;
-import java.io.PrintStream;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+package org.onap.dmaap.mr.tools;
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 java.io.IOException;
+import java.io.PrintStream;
+import org.onap.dmaap.mr.client.MRClient.MRApiException;
import org.onap.dmaap.mr.client.MRClientFactory;
import org.onap.dmaap.mr.client.MRIdentityManager;
-import org.onap.dmaap.mr.client.MRClient.MRApiException;
import org.onap.dmaap.mr.client.MRIdentityManager.ApiKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ApiKeyCommand implements Command<MRCommandContext> {
+ final Logger logger = LoggerFactory.getLogger(ApiKeyCommand.class);
-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 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 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 );
+ @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 ();
- }
- }
+ try {
+ switch (parts[0]) {
+ case "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");
+ }
+ break;
+ case "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?");
+ }
+ break;
+ case "update":
+ tm.updateCurrentApiKey(parts[1], parts[2]);
+ out.println("Updated");
+ break;
+ case "revoke":
+ tm.deleteCurrentApiKey();
+ out.println("Updated");
+ break;
+ default:
+ throw new CommandNotReadyException("The command " + parts[0] + " is not available");
+ }
+ } catch (HttpObjectNotFoundException e) {
+ out.println("Object not found: " + e.getMessage());
+ logger.error("HttpObjectNotFoundException: ", e);
+ } catch (HttpException e) {
+ out.println("HTTP exception: " + e.getMessage());
+ logger.error("HttpException: ", e);
+ } catch (MRApiException e) {
+ out.println("API exception: " + e.getMessage());
+ logger.error("MRApiException: ", e);
+ } catch (IOException e) {
+ out.println("IO exception: " + e.getMessage());
+ logger.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" );
- }
+ @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/org/onap/dmaap/mr/tools/AuthCommand.java b/src/main/java/org/onap/dmaap/mr/tools/AuthCommand.java
index 26a70f0..b3657ee 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/AuthCommand.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/AuthCommand.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,53 +19,45 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
-package org.onap.dmaap.mr.tools;
-import java.io.PrintStream;
+package org.onap.dmaap.mr.tools;
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
- {
- }
+import java.io.PrintStream;
+
+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 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 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"
- };
- }
+ @Override
+ public String[] getMatches() {
+ return new String[] {
+ "auth (\\S*) (\\S*)",
+ "noauth"
+ };
+ }
}
diff --git a/src/main/java/org/onap/dmaap/mr/tools/ClusterCommand.java b/src/main/java/org/onap/dmaap/mr/tools/ClusterCommand.java
index c4ef5e4..60c0380 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/ClusterCommand.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/ClusterCommand.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,64 +19,52 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
-package org.onap.dmaap.mr.tools;
-import java.io.PrintStream;
+package org.onap.dmaap.mr.tools;
import com.att.nsa.cmdtool.Command;
import com.att.nsa.cmdtool.CommandNotReadyException;
+import java.io.PrintStream;
import org.onap.dmaap.mr.client.impl.MRConsumerImpl;
-public class ClusterCommand implements Command<MRCommandContext>
-{
+public class ClusterCommand implements Command<MRCommandContext> {
- @Override
- public String[] getMatches ()
- {
- return new String[]{
- "cluster",
- "cluster (\\S*)?",
- };
- }
+ @Override
+ public String[] getMatches() {
+ return new String[] {
+ "cluster",
+ "cluster (\\S*)?",
+ };
+ }
- @Override
- public void checkReady ( MRCommandContext context ) throws CommandNotReadyException
- {
- }
+ @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 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 ..." );
- }
+ @Override
+ public void displayHelp(PrintStream out) {
+ out.println("cluster host1 host2 ...");
+ }
}
diff --git a/src/main/java/org/onap/dmaap/mr/tools/MRCommandContext.java b/src/main/java/org/onap/dmaap/mr/tools/MRCommandContext.java
index 5d13b30..0ccd6bf 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/MRCommandContext.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/MRCommandContext.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,84 +19,87 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
-package org.onap.dmaap.mr.tools;
-import java.util.Collection;
-import java.util.LinkedList;
+package org.onap.dmaap.mr.tools;
import com.att.nsa.apiClient.http.HttpClient;
import com.att.nsa.apiClient.http.HttpTracer;
import com.att.nsa.cmdtool.CommandContext;
+import java.util.Collection;
+import java.util.LinkedList;
import org.onap.dmaap.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;
+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/org/onap/dmaap/mr/tools/MRTool.java b/src/main/java/org/onap/dmaap/mr/tools/MRTool.java
deleted file mode 100644
index a37fa79..0000000
--- a/src/main/java/org/onap/dmaap/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 org.onap.dmaap.mr.tools;
-
-import java.io.IOException;
-
-import com.att.nsa.cmdtool.CommandLineTool;
-import org.onap.dmaap.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/org/onap/dmaap/mr/tools/MessageCommand.java b/src/main/java/org/onap/dmaap/mr/tools/MessageCommand.java
index 451aed5..5d8bfb8 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/MessageCommand.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/MessageCommand.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,114 +19,90 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
+
package org.onap.dmaap.mr.tools;
+import com.att.nsa.cmdtool.Command;
+import com.att.nsa.cmdtool.CommandNotReadyException;
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 org.onap.dmaap.mr.client.MRBatchingPublisher;
import org.onap.dmaap.mr.client.MRClientFactory;
import org.onap.dmaap.mr.client.MRConsumer;
-import org.onap.dmaap.mr.client.MRPublisher.message;
+import org.onap.dmaap.mr.client.MRPublisher.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MessageCommand implements Command<MRCommandContext> {
+ final Logger logger = LoggerFactory.getLogger(MessageCommand.class);
+
+ private static final String SENDING_PROBLEM_MESSAGE = "Problem sending 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 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 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 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(SENDING_PROBLEM_MESSAGE + e.getMessage());
+ logger.error(SENDING_PROBLEM_MESSAGE, e);
+ } finally {
+ List<Message> left = null;
+ try {
+ left = pub.close(500, TimeUnit.MILLISECONDS);
+ } catch (IOException e) {
+ out.println(SENDING_PROBLEM_MESSAGE + e.getMessage());
+ logger.error(SENDING_PROBLEM_MESSAGE, e);
+ } catch (InterruptedException e) {
+ out.println(SENDING_PROBLEM_MESSAGE + e.getMessage());
+ logger.error(SENDING_PROBLEM_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>" );
- }
+ @Override
+ public void displayHelp(PrintStream out) {
+ out.println("post <topicName> <partition> <message>");
+ out.println("read <topicName> <consumerGroup> <consumerId>");
+ }
}
diff --git a/src/main/java/org/onap/dmaap/mr/tools/ToolsUtil.java b/src/main/java/org/onap/dmaap/mr/tools/ToolsUtil.java
index 72e7fbf..ef9e103 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/ToolsUtil.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/ToolsUtil.java
@@ -4,12 +4,14 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -28,13 +30,13 @@ 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 ();
- }
+ 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/org/onap/dmaap/mr/tools/TopicCommand.java b/src/main/java/org/onap/dmaap/mr/tools/TopicCommand.java
index 278b04f..e8ad076 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/TopicCommand.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/TopicCommand.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,205 +19,160 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
-package org.onap.dmaap.mr.tools;
-
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.Set;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+package org.onap.dmaap.mr.tools;
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 java.io.IOException;
+import java.io.PrintStream;
+import java.util.Set;
import org.onap.dmaap.mr.client.MRClientFactory;
import org.onap.dmaap.mr.client.MRTopicManager;
import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TopicCommand implements Command<MRCommandContext> {
+ final Logger logger = LoggerFactory.getLogger(TopicCommand.class);
+
+ private static final String REQUEST_ERROR_MESSAGE = "Problem with request: ";
+ private static final String IOEXCEPTION_MESSAGE = "IOException: ";
+ private static final String HTTP_EXCEPTION_MESSAGE = "HttpException: ";
+
+ @Override
+ public String[] getMatches() {
+ return new String[] {
+ "topic (list)",
+ "topic (list) (\\S*)",
+ "topic (create) (\\S*) (\\S*) (\\S*)",
+ "topic (grant|revoke) (read|write) (\\S*) (\\S*)",
+ };
+ }
-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 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);
- @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 {
+ switch (parts[0]) {
+ case "list":
+ try {
+ if (parts.length == 1) {
+ for (String topic : tm.getTopics()) {
+ out.println(topic);
+ }
+ } else {
+ final TopicInfo ti = tm.getTopicMetadata(parts[1]);
- 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 owner = ti.getOwner ();
- out.println ( " owner: " + ( owner == null ? "<none>" : owner ) );
+ final String desc = ti.getDescription();
+ out.println("description: " + (desc == null ? "<none>" : desc));
- 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> 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(REQUEST_ERROR_MESSAGE + x.getMessage());
+ logger.error(IOEXCEPTION_MESSAGE, x);
+ } catch (HttpObjectNotFoundException e) {
+ out.println("Not found: " + e.getMessage());
+ logger.error("HttpObjectNotFoundException: ", e);
+ }
+ break;
+ case "create":
+ try {
+ final int partitions = Integer.parseInt(parts[2]);
+ final int replicas = Integer.parseInt(parts[3]);
- 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 ();
- }
- }
+ tm.createTopic(parts[1], "", partitions, replicas);
+ } catch (HttpException e) {
+ out.println(REQUEST_ERROR_MESSAGE + e.getMessage());
+ logger.error(HTTP_EXCEPTION_MESSAGE, e);
+ } catch (IOException e) {
+ out.println(REQUEST_ERROR_MESSAGE + e.getMessage());
+ logger.error(IOEXCEPTION_MESSAGE, e);
+ } catch (NumberFormatException e) {
+ out.println(REQUEST_ERROR_MESSAGE + e.getMessage());
+ logger.error("NumberFormatException: ", e);
+ }
+ break;
+ case "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(REQUEST_ERROR_MESSAGE + e.getMessage());
+ logger.error(HTTP_EXCEPTION_MESSAGE, e);
+ } catch (IOException e) {
+ out.println(REQUEST_ERROR_MESSAGE + e.getMessage());
+ logger.error(IOEXCEPTION_MESSAGE, e);
+ }
+ break;
+ case "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(REQUEST_ERROR_MESSAGE + e.getMessage());
+ logger.error(HTTP_EXCEPTION_MESSAGE, e);
+ } catch (IOException e) {
+ out.println(REQUEST_ERROR_MESSAGE + e.getMessage());
+ logger.error(IOEXCEPTION_MESSAGE, e);
+ }
+ break;
+ default:
+ throw new CommandNotReadyException("The command " + parts[0] + " is not available");
+ }
+ } 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>" );
- }
+ @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/org/onap/dmaap/mr/tools/TraceCommand.java b/src/main/java/org/onap/dmaap/mr/tools/TraceCommand.java
index 95edf5b..a167c0f 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/TraceCommand.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/TraceCommand.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,102 +19,87 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
+
package org.onap.dmaap.mr.tools;
+import com.att.nsa.apiClient.http.HttpTracer;
+import com.att.nsa.cmdtool.Command;
+import com.att.nsa.cmdtool.CommandNotReadyException;
+
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
- {
- }
+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 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(K_LINE_BREAK);
+ out.println(">>> " + method + " " + uri.toString());
+ for (Map.Entry<String, List<String>> e : headers.entrySet()) {
+ final StringBuilder vals = new StringBuilder();
+ for (String val : e.getValue()) {
+ if (vals.length() > 0) vals.append(", ");
+ vals.append(val);
+ }
+ out.println(">>> " + e.getKey() + ": " + vals);
+ }
+ if (entity != null) {
+ out.println();
+ out.println(new String(entity));
+ }
+ out.println(K_LINE_BREAK);
+ }
- @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 inbound(Map<String, List<String>> headers, int statusCode, String responseLine, byte[] entity) {
+ out.println(K_LINE_BREAK);
+ out.println("<<< " + responseLine);
+ for (Map.Entry<String, List<String>> e : headers.entrySet()) {
+ final StringBuilder vals = new StringBuilder();
+ for (String val : e.getValue()) {
+ if (vals.length() > 0) {
+ vals.append(", ");
+ }
+ vals.append(val);
+ }
+ out.println("<<< " + e.getKey() + ": " + vals);
+ }
+ if (entity != null) {
+ out.println();
+ out.println(new String(entity));
+ }
+ out.println(K_LINE_BREAK);
+ }
+ });
+ } 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 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)"
- };
- }
+ @Override
+ public String[] getMatches() {
+ return new String[] {
+ "trace (on)",
+ "trace (off)"
+ };
+ }
- private static final String kLineBreak = "======================================================================";
+ private static final String K_LINE_BREAK = "======================================================================";
}
diff --git a/src/main/java/org/onap/dmaap/mr/tools/ValidatorUtil.java b/src/main/java/org/onap/dmaap/mr/tools/ValidatorUtil.java
index cdba1e0..d01c34f 100644
--- a/src/main/java/org/onap/dmaap/mr/tools/ValidatorUtil.java
+++ b/src/main/java/org/onap/dmaap/mr/tools/ValidatorUtil.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,158 +19,200 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
+
package org.onap.dmaap.mr.tools;
import java.util.Properties;
-
-import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
+import org.onap.dmaap.mr.client.ProtocolType;
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" );
- }
-
- }
+ private static final String ID = "id";
+ private static final String AUTH_KEY = "authKey";
+ private static final String AUTH_DATE = "authDate";
+ private static final String PASSWORD = "password";
+ private static final String USERNAME = "username";
+ private static final String HOST = "host";
+ private static final String DME2PREFERRED_ROUTER_FILE_PATH = "DME2preferredRouterFilePath";
+ private static final String TOPIC = "topic";
+ private static final String TRANSPORT_TYPE = "TransportType";
+ private static final String MAX_BATCH_SIZE = "maxBatchSize";
+ private static final String MAX_AGE_MS = "maxAgeMs";
+ private static final String MESSAGE_SENT_THREAD_OCCURRENCE_OLD = "MessageSentThreadOccurance";
+ private static final String MESSAGE_SENT_THREAD_OCCURRENCE = "MessageSentThreadOccurrence";
+ private static final String GROUP = "group";
+ private static final String SERVICE_NAME = "ServiceName";
+ private static final String PARTNER = "Partner";
+ private static final String ROUTE_OFFER = "routeOffer";
+ private static final String PROTOCOL = "Protocol";
+ private static final String METHOD_TYPE = "MethodType";
+ private static final String CONTENT_TYPE = "contenttype";
+ private static final String LATITUDE = "Latitude";
+ private static final String LONGITUDE = "Longitude";
+ private static final String AFT_ENVIRONMENT = "AFT_ENVIRONMENT";
+ private static final String VERSION = "Version";
+ private static final String ENVIRONMENT = "Environment";
+ private static final String SUB_CONTEXT_PATH = "SubContextPath";
+ private static final String SESSION_STICKINESS_REQUIRED = "sessionstickinessrequired";
+
+ public static final String IS_NEEDED = " is needed";
+
+ private ValidatorUtil() {
+
+ }
+
+ public static void validatePublisher(Properties props) {
+ String transportType = props.getProperty(TRANSPORT_TYPE);
+ if (ProtocolType.DME2.getValue().equalsIgnoreCase(transportType)) {
+ validateForDME2(props);
+ } else {
+ validateForNonDME2(props);
+ }
+ String maxBatchSize = props.getProperty(MAX_BATCH_SIZE, "");
+ if (maxBatchSize.isEmpty()) {
+ throw new IllegalArgumentException(MAX_BATCH_SIZE + IS_NEEDED);
+ }
+ String maxAgeMs = props.getProperty(MAX_AGE_MS, "");
+ if (maxAgeMs.isEmpty()) {
+ throw new IllegalArgumentException(MAX_AGE_MS + IS_NEEDED);
+ }
+
+ String messageSentThreadOccurrence = props.getProperty(MESSAGE_SENT_THREAD_OCCURRENCE);
+ if (messageSentThreadOccurrence == null || messageSentThreadOccurrence.isEmpty()) {
+ messageSentThreadOccurrence = props.getProperty(MESSAGE_SENT_THREAD_OCCURRENCE_OLD);
+ }
+ if (messageSentThreadOccurrence == null || messageSentThreadOccurrence.isEmpty()) {
+ throw new IllegalArgumentException(MESSAGE_SENT_THREAD_OCCURRENCE + IS_NEEDED);
+ }
+ try {
+ Integer.parseInt(messageSentThreadOccurrence);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(MESSAGE_SENT_THREAD_OCCURRENCE + " must be an integer");
+ }
+
+ }
+
+ public static void validateSubscriber(Properties props) {
+ String transportType = props.getProperty(TRANSPORT_TYPE);
+ if (ProtocolType.DME2.getValue().equalsIgnoreCase(transportType)) {
+ validateForDME2(props);
+ } else {
+ validateForNonDME2(props);
+ }
+ String group = props.getProperty(GROUP, "");
+ if (group.isEmpty()) {
+ throw new IllegalArgumentException(GROUP + IS_NEEDED);
+ }
+ String id = props.getProperty(ID, "");
+ if (id.isEmpty()) {
+ throw new IllegalArgumentException("Consumer (" + ID + ")" + IS_NEEDED);
+ }
+ }
+
+ private static void validateForDME2(Properties props) {
+ String serviceName = props.getProperty(SERVICE_NAME, "");
+ if (serviceName.isEmpty()) {
+ throw new IllegalArgumentException(SERVICE_NAME + IS_NEEDED);
+ }
+ String topic = props.getProperty(TOPIC, "");
+ if (topic.isEmpty()) {
+ throw new IllegalArgumentException(TOPIC + IS_NEEDED);
+ }
+ String username = props.getProperty(USERNAME, "");
+ if (username.isEmpty()) {
+ throw new IllegalArgumentException(USERNAME + IS_NEEDED);
+ }
+ String password = props.getProperty(PASSWORD, "");
+ if (password.isEmpty()) {
+ throw new IllegalArgumentException(PASSWORD + IS_NEEDED);
+ }
+ String dme2preferredRouterFilePath = props.getProperty(DME2PREFERRED_ROUTER_FILE_PATH, "");
+ if (dme2preferredRouterFilePath.isEmpty()) {
+ throw new IllegalArgumentException(DME2PREFERRED_ROUTER_FILE_PATH + IS_NEEDED);
+ }
+ String partner = props.getProperty(PARTNER, "");
+ String routeOffer = props.getProperty(ROUTE_OFFER, "");
+ if (partner.isEmpty() && routeOffer.isEmpty()) {
+ throw new IllegalArgumentException(PARTNER + " or " + ROUTE_OFFER + IS_NEEDED);
+ }
+ String protocol = props.getProperty(PROTOCOL, "");
+ if (protocol.isEmpty()) {
+ throw new IllegalArgumentException(PROTOCOL + IS_NEEDED);
+ }
+ String methodType = props.getProperty(METHOD_TYPE, "");
+ if (methodType.isEmpty()) {
+ throw new IllegalArgumentException(METHOD_TYPE + IS_NEEDED);
+ }
+ String contentType = props.getProperty(CONTENT_TYPE, "");
+ if (contentType.isEmpty()) {
+ throw new IllegalArgumentException(CONTENT_TYPE + IS_NEEDED);
+ }
+ String latitude = props.getProperty(LATITUDE, "");
+ if (latitude.isEmpty()) {
+ throw new IllegalArgumentException(LATITUDE + IS_NEEDED);
+ }
+ String longitude = props.getProperty(LONGITUDE, "");
+ if (longitude.isEmpty()) {
+ throw new IllegalArgumentException(LONGITUDE + IS_NEEDED);
+ }
+ String aftEnv = props.getProperty(AFT_ENVIRONMENT, "");
+ if (aftEnv.isEmpty()) {
+ throw new IllegalArgumentException(AFT_ENVIRONMENT + IS_NEEDED);
+ }
+ String version = props.getProperty(VERSION, "");
+ if (version.isEmpty()) {
+ throw new IllegalArgumentException(VERSION + IS_NEEDED);
+ }
+ String environment = props.getProperty(ENVIRONMENT, "");
+ if (environment.isEmpty()) {
+ throw new IllegalArgumentException(ENVIRONMENT + IS_NEEDED);
+ }
+ String subContextPath = props.getProperty(SUB_CONTEXT_PATH, "");
+ if (subContextPath.isEmpty()) {
+ throw new IllegalArgumentException(SUB_CONTEXT_PATH + IS_NEEDED);
+ }
+ String sessionstickinessrequired = props.getProperty(SESSION_STICKINESS_REQUIRED, "");
+ if (sessionstickinessrequired.isEmpty()) {
+ throw new IllegalArgumentException(SESSION_STICKINESS_REQUIRED + IS_NEEDED);
+ }
+ }
+
+ private static void validateForNonDME2(Properties props) {
+ String host = props.getProperty(HOST, "");
+ if (host.isEmpty()) {
+ throw new IllegalArgumentException(HOST + IS_NEEDED);
+ }
+ String topic = props.getProperty(TOPIC, "");
+ if (topic.isEmpty()) {
+ throw new IllegalArgumentException(TOPIC + IS_NEEDED);
+ }
+ String contenttype = props.getProperty(CONTENT_TYPE, "");
+ if (contenttype.isEmpty()) {
+ throw new IllegalArgumentException(CONTENT_TYPE + IS_NEEDED);
+ }
+ String transportType = props.getProperty(TRANSPORT_TYPE);
+ if (!ProtocolType.HTTPNOAUTH.getValue().equalsIgnoreCase(transportType)) {
+ String username = props.getProperty(USERNAME, "");
+ if (username.isEmpty()) {
+ throw new IllegalArgumentException(USERNAME + IS_NEEDED);
+ }
+ String password = props.getProperty(PASSWORD, "");
+ if (password.isEmpty()) {
+ throw new IllegalArgumentException(PASSWORD + IS_NEEDED);
+ }
+ }
+ if (ProtocolType.AUTH_KEY.getValue().equalsIgnoreCase(transportType)) {
+ String authKey = props.getProperty(AUTH_KEY, "");
+ if (authKey.isEmpty()) {
+ throw new IllegalArgumentException(AUTH_KEY + IS_NEEDED);
+ }
+ String authDate = props.getProperty(AUTH_DATE, "");
+ if (authDate.isEmpty()) {
+ throw new IllegalArgumentException(AUTH_DATE + 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" );
- }
-
- }
- }
-
}