diff options
Diffstat (limited to 'src/main/java/org/onap/dmaap/mr/dme')
6 files changed, 464 insertions, 0 deletions
diff --git a/src/main/java/org/onap/dmaap/mr/dme/client/DefaultLoggingFailoverFaultHandler.java b/src/main/java/org/onap/dmaap/mr/dme/client/DefaultLoggingFailoverFaultHandler.java new file mode 100644 index 0000000..a44d858 --- /dev/null +++ b/src/main/java/org/onap/dmaap/mr/dme/client/DefaultLoggingFailoverFaultHandler.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============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.dme.client; + + + +import java.util.logging.Level; +import java.util.logging.Logger; + + +//import com.att.aft.dme2.api.util.DME2Constants; +//import com.att.aft.dme2.api.util.DME2ExchangeFaultContext; +//import com.att.aft.dme2.api.util.LogMessage; +//import com.att.aft.dme2.api.util.LogUtil; +public class DefaultLoggingFailoverFaultHandler /*implements DME2FailoverFaultHandler*/ { + //TODO: This code may be enable in the future when we implement DME2FailoverFaultHandler interface + /** The logger. */ + + +// @Override + +// // LogUtil.INSTANCE.report(logger, Level.WARNING, LogMessage.SEP_FAILOVER, context.getService(),context.getRequestURL(),context.getRouteOffer(),context.getResponseCode(),context.getException()); +// } +// @Override +// /** +// * The DME2Exchange already has a log message when the route offer is failed over. We dont need to log it again here. +// */ + +// //noop +// + +} + diff --git a/src/main/java/org/onap/dmaap/mr/dme/client/HeaderReplyHandler.java b/src/main/java/org/onap/dmaap/mr/dme/client/HeaderReplyHandler.java new file mode 100644 index 0000000..da0ba62 --- /dev/null +++ b/src/main/java/org/onap/dmaap/mr/dme/client/HeaderReplyHandler.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============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.dme.client; + + +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.att.aft.dme2.api.util.DME2ExchangeFaultContext; +import com.att.aft.dme2.api.util.DME2ExchangeReplyHandler; +import com.att.aft.dme2.api.util.DME2ExchangeResponseContext; +import org.onap.dmaap.mr.client.MRClientFactory; +import org.onap.dmaap.mr.client.impl.MRSimplerBatchPublisher; + + + + + + public class HeaderReplyHandler implements DME2ExchangeReplyHandler { + + private Logger fLog = LoggerFactory.getLogger ( this.getClass().getName () ); + + + @Override public void handleFault(DME2ExchangeFaultContext responseData) { + // TODO Auto-generated method stub + + } + @Override public void handleEndpointFault(DME2ExchangeFaultContext responseData) { + // TODO Auto-generated method stub + + } +@Override public void handleReply(DME2ExchangeResponseContext responseData) { + + if(responseData != null) { + MRClientFactory.DME2HeadersMap=responseData.getResponseHeaders(); + if (responseData.getResponseHeaders().get("transactionId")!=null) + fLog.info("Transaction Id : " + responseData.getResponseHeaders().get("transactionId")); + + } +} + +} diff --git a/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteReplyHandler.java b/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteReplyHandler.java new file mode 100644 index 0000000..967ccf3 --- /dev/null +++ b/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteReplyHandler.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============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.dme.client; +import java.io.File; +import java.io.FileWriter; +import java.io.InputStream; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.att.aft.dme2.api.util.DME2ExchangeFaultContext; +import com.att.aft.dme2.api.util.DME2ExchangeReplyHandler; +import com.att.aft.dme2.api.util.DME2ExchangeResponseContext; +import org.onap.dmaap.mr.client.MRClientFactory; +import org.onap.dmaap.mr.client.impl.MRSimplerBatchPublisher; + +public class PreferredRouteReplyHandler implements DME2ExchangeReplyHandler { + private Logger fLog = LoggerFactory.getLogger ( this.getClass().getName () ); + @Override public void handleReply(DME2ExchangeResponseContext responseData) { + + if(responseData != null) { + MRClientFactory.DME2HeadersMap=responseData.getResponseHeaders(); + if (responseData.getResponseHeaders().get("transactionId")!=null) + + fLog.info("Transaction_Id : " + responseData.getResponseHeaders().get("transactionId")); + + if(responseData.getRouteOffer() != null ){ + routeWriter("preferredRouteKey",responseData.getRouteOffer()); + + } + } +} + + @Override public void handleFault(DME2ExchangeFaultContext responseData) { + // TODO Auto-generated method stub + //StaticCache.getInstance().setHandleFaultInvoked(true); + } + @Override public void handleEndpointFault(DME2ExchangeFaultContext responseData) { + // TODO Auto-generated method stub + + } + public void routeWriter(String routeKey, String routeValue){ + + try(FileWriter routeWriter=new FileWriter(new File (MRSimplerBatchPublisher.routerFilePath))){ + routeWriter.write(routeKey+"="+routeValue); + routeWriter.close(); + + }catch(Exception ex){ + fLog.error("Reply Router Error " + ex); + } + + } +} diff --git a/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteRequestHandler.java b/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteRequestHandler.java new file mode 100644 index 0000000..4c2e546 --- /dev/null +++ b/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteRequestHandler.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============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.dme.client; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.att.aft.dme2.api.util.DME2ExchangeRequestContext; +import com.att.aft.dme2.api.util.DME2ExchangeRequestHandler; +import org.onap.dmaap.mr.client.MRClientFactory; + +public class PreferredRouteRequestHandler implements DME2ExchangeRequestHandler { + private Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + + @Override + public void handleRequest(DME2ExchangeRequestContext requestData) { + + if (requestData != null) { + + requestData.setPreferredRouteOffer(readRoute("preferredRouteKey")); + } + } + + public String readRoute(String routeKey) { + + try { + + MRClientFactory.prop.load(MRClientFactory.routeReader); + + } catch (Exception ex) { + logger.error("Request Router Error " + ex); + } + return MRClientFactory.prop.getProperty(routeKey); + } +} diff --git a/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExampleConsumer.java b/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExampleConsumer.java new file mode 100644 index 0000000..6fb02a5 --- /dev/null +++ b/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExampleConsumer.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * ============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.dme.client; + +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.core.MultivaluedMap; + +import org.onap.dmaap.mr.client.MRClientFactory; +import org.onap.dmaap.mr.client.MRConsumer; + +import java.util.List; + +public class SimpleExampleConsumer { + + private static final Logger logger = LoggerFactory.getLogger(SimpleExampleConsumer.class); + + private SimpleExampleConsumer() { + } + + public static void main(String[] args) { + + long count = 0; + long nextReport = 5000; + String key; + + final long startMs = System.currentTimeMillis(); + + try { + + final MRConsumer cc = MRClientFactory.createConsumer("D:\\SG\\consumer.properties"); + while (true) { + for (String msg : cc.fetch()) { + logger.debug("Message Received: " + msg); + } + // Header for DME2 Call. + MultivaluedMap<String, Object> headersMap = MRClientFactory.HTTPHeadersMap; + for (MultivaluedMap.Entry<String, List<Object>> entry : headersMap.entrySet()) { + key = entry.getKey(); + logger.debug("Header Key " + key); + logger.debug("Header Value " + headersMap.get(key)); + } + // Header for HTTP Call. + + Map<String, String> dme2headersMap = MRClientFactory.DME2HeadersMap; + for (Map.Entry<String, String> entry : dme2headersMap.entrySet()) { + key = entry.getKey(); + logger.debug("Header Key " + key); + logger.debug("Header Value " + dme2headersMap.get(key)); + } + + if (count > nextReport) { + nextReport += 5000; + + final long endMs = System.currentTimeMillis(); + final long elapsedMs = endMs - startMs; + final double elapsedSec = elapsedMs / 1000.0; + final double eps = count / elapsedSec; + } + } + } catch (Exception x) { + logger.error(x.toString()); + } + } +} diff --git a/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExamplePublisher.java b/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExamplePublisher.java new file mode 100644 index 0000000..edb3994 --- /dev/null +++ b/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExamplePublisher.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * ============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.dme.client; + + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import java.util.concurrent.TimeUnit; + +import javax.ws.rs.core.MultivaluedMap; + +import org.json.JSONObject; + +import org.onap.dmaap.mr.client.MRBatchingPublisher; +import org.onap.dmaap.mr.client.MRClientFactory; +import org.onap.dmaap.mr.client.MRPublisher.message; + +/** + * An example of how to use the Java publisher. + * + * @author author + */ +public class SimpleExamplePublisher { + static String content = null; + static String messageSize = null; + static String transport = null; + static String messageCount = null; + + public void publishMessage(String producerFilePath) throws IOException, InterruptedException { + + // create our publisher + + // publish some messages + + + StringBuilder sb = new StringBuilder(); + final MRBatchingPublisher pub = MRClientFactory.createBatchingPublisher(producerFilePath); + + if (content.equalsIgnoreCase("text/plain")) { + for (int i = 0; i < Integer.parseInt(messageCount); i++) { + for (int j = 0; j < Integer.parseInt(messageSize); j++) { + sb.append("T"); + } + + pub.send(sb.toString()); + } + } else if (content.equalsIgnoreCase("application/cambria")) { + for (int i = 0; i < Integer.parseInt(messageCount); i++) { + for (int j = 0; j < Integer.parseInt(messageSize); j++) { + sb.append("C"); + } + + pub.send("Key", sb.toString()); + } + } else if (content.equalsIgnoreCase("application/json")) { + for (int i = 0; i < Integer.parseInt(messageCount); i++) { + + final JSONObject msg12 = new JSONObject(); + msg12.put("Name", "DMaaP Reference Client to Test jason Message"); + + pub.send(msg12.toString()); + + } + } + + // ... + + // close the publisher to make sure everything's sent before exiting. + // The batching + // publisher interface allows the app to get the set of unsent messages. + // It could + // write them to disk, for example, to try to send them later. + /* final List<message> stuck = pub.close(20, TimeUnit.SECONDS); + if (stuck.size() > 0) { + System.err.println(stuck.size() + " messages unsent"); + } else { + System.out.println("Clean exit; all messages sent."); + }*/ + + if (transport.equalsIgnoreCase("HTTP")) { + MultivaluedMap<String, Object> headersMap = MRClientFactory.HTTPHeadersMap; + for (String key : headersMap.keySet()) { + System.out.println("Header Key " + key); + System.out.println("Header Value " + headersMap.get(key)); + } + } else { + Map<String, String> dme2headersMap = MRClientFactory.DME2HeadersMap; + for (String key : dme2headersMap.keySet()) { + System.out.println("Header Key " + key); + System.out.println("Header Value " + dme2headersMap.get(key)); + } + } + + } + + public static void main(String[] args) throws InterruptedException, Exception { + + String producerFilePath = args[0]; + content = args[1]; + messageSize = args[2]; + transport = args[3]; + messageCount = args[4]; + + + + + + SimpleExamplePublisher publisher = new SimpleExamplePublisher(); + + publisher.publishMessage("D:\\SG\\producer.properties"); + } + +} |