Omaha #2926 switched textdb to thrift client

Change-Id: I80a55506fa1e6d8780c0d3dbfb4b3c82b1aac9f1

Former-commit-id: 856ef48bab005bdb7de9dd4145fafc7fe12084f5
This commit is contained in:
Brian Clements 2014-08-18 12:42:22 -05:00
parent 6370aaba96
commit 1bbf5d7346
25 changed files with 715 additions and 602 deletions

View file

@ -25,15 +25,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import com.raytheon.edex.uengine.exception.MicroEngineException; import com.raytheon.edex.uengine.exception.MicroEngineException;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.message.Header; import com.raytheon.uf.common.message.Header;
import com.raytheon.uf.common.message.Message; import com.raytheon.uf.common.message.Message;
import com.raytheon.uf.common.message.Property; import com.raytheon.uf.common.message.Property;
import com.raytheon.uf.common.message.response.AbstractResponseMessage; import com.raytheon.uf.common.message.response.AbstractResponseMessage;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.util.FileUtil; import com.raytheon.uf.common.util.FileUtil;
import com.raytheon.uf.common.util.RunProcess; import com.raytheon.uf.common.util.RunProcess;
import com.raytheon.uf.edex.core.EDEXUtil; import com.raytheon.uf.edex.core.EDEXUtil;
@ -56,6 +53,7 @@ import com.raytheon.uf.edex.core.EDEXUtil;
* Added logic to utilize the trigger. * Added logic to utilize the trigger.
* Sep 19, 2011 10955 rferrel Use RunProcess * Sep 19, 2011 10955 rferrel Use RunProcess
* 05/25/2012 DR 15015 D. Friedman Use helper script to launch triggers. * 05/25/2012 DR 15015 D. Friedman Use helper script to launch triggers.
* Aug 22, 2014 2926 bclement compatibility changes with new textdb service
* </pre> * </pre>
* *
* @author mfegan * @author mfegan
@ -133,10 +131,15 @@ public class LdadMicroEngine extends AMicroEngine {
*/ */
private String retrieveTextProduct(String prodID) throws Exception { private String retrieveTextProduct(String prodID) throws Exception {
Message message = createProductRequestMessage(prodID); Message message = createProductRequestMessage(prodID);
String xml = SerializationUtil.marshalToXml(message);
Object response = EDEXUtil.getMessageProducer().sendSync(TEXT_DB_QUEUE, Object response = EDEXUtil.getMessageProducer().sendSync(TEXT_DB_QUEUE,
xml); message);
return extractProductFromResponse(response.toString()); if (response instanceof Message) {
return extractProductFromResponse((Message) response);
} else {
throw new MicroEngineException(
"Unexpected return type from textdb service: "
+ response.getClass());
}
} }
/** /**
@ -166,10 +169,10 @@ public class LdadMicroEngine extends AMicroEngine {
Message message = new Message(); Message message = new Message();
Header header = new Header(); Header header = new Header();
List<Property> properties = new ArrayList<Property>(); List<Property> properties = new ArrayList<Property>();
properties.add(new Property("VIEW", AsciiToHex("text"))); properties.add(new Property("VIEW", "text"));
properties.add(new Property("OP", AsciiToHex("GET"))); properties.add(new Property("OP", "GET"));
properties.add(new Property("SUBOP", AsciiToHex("PROD"))); properties.add(new Property("SUBOP", "PROD"));
properties.add(new Property("AFOSCMD", AsciiToHex(prodID))); properties.add(new Property("AFOSCMD", prodID));
header.setProperties(properties.toArray(new Property[] {})); header.setProperties(properties.toArray(new Property[] {}));
message.setHeader(header); message.setHeader(header);
return message; return message;
@ -195,15 +198,13 @@ public class LdadMicroEngine extends AMicroEngine {
* @throws Exception * @throws Exception
* if an error occurs * if an error occurs
*/ */
private String extractProductFromResponse(String response) throws Exception { private String extractProductFromResponse(Message reply) throws Exception {
StringBuffer retVal = new StringBuffer(); StringBuffer retVal = new StringBuffer();
Message reply = (Message) SerializationUtil.unmarshalFromXml(response);
Header header = reply.getHeader(); Header header = reply.getHeader();
if (header != null && header.getProperties() != null) { if (header != null && header.getProperties() != null) {
for (Property property : header.getProperties()) { for (Property property : header.getProperties()) {
if (property.getName().equalsIgnoreCase("stdout")) { if (property.getName().equalsIgnoreCase("stdout")) {
String value = hexToAscii(property.getValue()); retVal.append(property.getValue()).append("\n");
retVal.append(value).append("\n");
} }
} }
} }
@ -250,34 +251,6 @@ public class LdadMicroEngine extends AMicroEngine {
RunProcess.getRunProcess() RunProcess.getRunProcess()
.exec(script, strEnv.toArray(new String[] {})); .exec(script, strEnv.toArray(new String[] {}));
} }
/**
* Converts an ASCII string to a binary representation. This conversion is
* required as Text Database Server expects all Header Property values to be
* HEX encoded.
*
* @param string
* the string to convert
* @return the converted string
*/
private String AsciiToHex(String string) {
return new HexBinaryAdapter().marshal(string.getBytes());
}
/**
* Converts a HEX encoded string to plain ASCII. This conversion is required
* as Text Database Server expects all Header Property values to be HEX
* encoded.
*
* @param hexString
* the HEX encoded string
*
* @return the plain text string
*/
private String hexToAscii(String hexString) {
byte[] b = new HexBinaryAdapter().unmarshal(hexString);
return new String(b);
}
/** /**
* Finds a helper script that should be used to launch triggers. The helper * Finds a helper script that should be used to launch triggers. The helper

View file

@ -1,89 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.dataplugin.text.dbsrv;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import com.raytheon.uf.common.message.Header;
/**
* Utilities for hexadecimal property values
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 15, 2014 2536 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class PropConverter {
/**
* ASCII to HEX conversion.
*
* @param string
* ascii string
* @return hex code
*/
public static String asciiToHex(String string) {
return new HexBinaryAdapter().marshal(string.getBytes());
}
/**
* HEX To ASCII conversion
*
* @param hexString
* @return ascii string
*/
public static String hexToAscii(String hexString) {
byte[] b = new HexBinaryAdapter().unmarshal(hexString);
return new String(b);
}
/**
* Get hexadecimal property value. Converts value from hex to ASCII (if
* non-null).
*
* @param header
* contains message header.
* @param propName
* contains property name.
* @return property value or null if property is not in header
*/
public static String getProperty(Header header, String propName) {
String result = null;
String value = header.getProperty(propName);
if (value != null) {
result = hexToAscii(value);
}
return result;
}
}

View file

@ -34,11 +34,12 @@ import com.raytheon.uf.common.message.Property;
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Nov 3, 2008 jkorman Initial creation * Nov 3, 2008 jkorman Initial creation
* 28May2010 cjeanbap Added operational functionality. * 28May2010 cjeanbap Added operational functionality.
* 02Aug2010 2187 cjeanbap Update variable/method signature to be consistent. * 02Aug2010 2187 cjeanbap Update variable/method signature to be consistent.
* 29Jan2013 1496 rferrel Added methods clearProductIds and clone. * 29Jan2013 1496 rferrel Added methods clearProductIds and clone.
* May 15, 2014 2536 bclement moved from uf.edex.textdbsrv * May 15, 2014 2536 bclement moved from uf.edex.textdbsrv
* Aug 22, 2014 2926 bclement compatibility changes with new textdb service
* *
* </pre> * </pre>
* *
@ -431,7 +432,7 @@ public class TextDBQuery {
for (Property property : properties) { for (Property property : properties) {
String s = property.getValue(); String s = property.getValue();
if (s != null) { if (s != null) {
property.setValue(PropConverter.asciiToHex(s)); property.setValue(s);
} }
} }
Property[] p = new Property[properties.size()]; Property[] p = new Property[properties.size()];
@ -453,7 +454,7 @@ public class TextDBQuery {
for (Property p : properties) { for (Property p : properties) {
String s = p.getValue(); String s = p.getValue();
if (s != null) { if (s != null) {
p.setValue(PropConverter.hexToAscii(s)); p.setValue(s);
} }
} }
} }

View file

@ -71,9 +71,7 @@
<route id="textdbsrvinternal"> <route id="textdbsrvinternal">
<from uri="direct-vm:int.textdb.request" /> <from uri="direct-vm:int.textdb.request" />
<bean ref="serializationUtil" method="unmarshalFromXml" />
<bean ref="textdbsrv" method="processMessage" /> <bean ref="textdbsrv" method="processMessage" />
<bean ref="serializationUtil" method="marshalToXml" />
</route> </route>
<route id="subscriptionNotify"> <route id="subscriptionNotify">

View file

@ -62,10 +62,6 @@
</bean> </bean>
<!-- textdb --> <!-- textdb -->
<bean id="textDbSrvWrapper" class = "com.raytheon.uf.edex.plugin.text.dbsrv.TextDBSrvWrapper">
<property name="textdbSrv" ref="textdbsrv"/>
<property name="byteLimitInMB" value="${textdbsrv.byteLimitInMB}"/>
</bean>
<bean id="executeAfosCmdHandler" class="com.raytheon.uf.edex.plugin.text.handler.ExecuteAfosCmdHandler" /> <bean id="executeAfosCmdHandler" class="com.raytheon.uf.edex.plugin.text.handler.ExecuteAfosCmdHandler" />
<bean factory-bean="handlerRegistry" factory-method="register"> <bean factory-bean="handlerRegistry" factory-method="register">
@ -98,6 +94,15 @@
<constructor-arg value="com.raytheon.uf.common.dataplugin.text.request.RemoteRetrievalRequest"/> <constructor-arg value="com.raytheon.uf.common.dataplugin.text.request.RemoteRetrievalRequest"/>
<constructor-arg ref="remoteRetrievalHandler"/> <constructor-arg ref="remoteRetrievalHandler"/>
</bean> </bean>
<bean factory-bean="handlerRegistry" factory-method="register">
<constructor-arg value="com.raytheon.uf.edex.plugin.text.dbsrv.TextDBRequest"/>
<constructor-arg>
<bean class="com.raytheon.uf.edex.plugin.text.dbsrv.TextDBRequestHandler">
<constructor-arg ref="textdbsrv" />
</bean>
</constructor-arg>
</bean>
<bean id="remoteRetrievalManager" class="com.raytheon.uf.edex.plugin.text.handler.RemoteRetrievalManager"> <bean id="remoteRetrievalManager" class="com.raytheon.uf.edex.plugin.text.handler.RemoteRetrievalManager">
<!-- <property name="remoteRetrievalExternalURI" value="direct-vm:remoteRetrievalExternalRoute" /> --> <!-- <property name="remoteRetrievalExternalURI" value="direct-vm:remoteRetrievalExternalRoute" /> -->
@ -129,17 +134,9 @@
<proxy id="textdbRemoteRetrievalTarget" <proxy id="textdbRemoteRetrievalTarget"
serviceInterface="com.raytheon.uf.edex.plugin.text.handler.RemoteRetrievalManager$IRRDelegate" serviceInterface="com.raytheon.uf.edex.plugin.text.handler.RemoteRetrievalManager$IRRDelegate"
serviceUrl="direct-vm:remoteRetrievalExternalRoute" /> serviceUrl="direct-vm:remoteRetrievalExternalRoute" />
<endpoint id="textdbsrvXml_from"
uri="jetty:http://0.0.0.0:${HTTP_PORT}/services/textdbsrv?disableStreamCache=true" />
<endpoint id="subscriptionHTTP_from" <endpoint id="subscriptionHTTP_from"
uri="jetty:http://0.0.0.0:${HTTP_PORT}/services/subscribe?disableStreamCache=true" /> uri="jetty:http://0.0.0.0:${HTTP_PORT}/services/subscribe?disableStreamCache=true" />
<route id="textdbsrvXml">
<from uri="ref:textdbsrvXml_from" />
<bean ref="textDbSrvWrapper" method="executeTextDBMessage" />
</route>
<route id="remoteRetrievalExternal"> <route id="remoteRetrievalExternal">
<from uri="direct-vm:remoteRetrievalExternalRoute" /> <from uri="direct-vm:remoteRetrievalExternalRoute" />

View file

@ -0,0 +1,77 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.plugin.text.dbsrv;
import com.raytheon.uf.common.message.Message;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.serialization.comm.IServerRequest;
/**
* Object used by thrift clients to make textdb requests
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 18, 2014 2926 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
@DynamicSerialize
public class TextDBRequest implements IServerRequest {
@DynamicSerializeElement
private Message message;
/**
*
*/
public TextDBRequest() {
}
/**
* @param message
*/
public TextDBRequest(Message message) {
this.message = message;
}
/**
* @return the message
*/
public Message getMessage() {
return message;
}
/**
* @param message
* the message to set
*/
public void setMessage(Message message) {
this.message = message;
}
}

View file

@ -0,0 +1,64 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.plugin.text.dbsrv;
import com.raytheon.uf.common.serialization.comm.IRequestHandler;
/**
* Handles requests from the textdb client
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 18, 2014 2926 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class TextDBRequestHandler implements
IRequestHandler<TextDBRequest> {
private final TextDBSrv textdbSrv;
/**
* @param textdbSrv
*/
public TextDBRequestHandler(TextDBSrv textdbSrv) {
this.textdbSrv = textdbSrv;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.common.serialization.comm.IRequestHandler#handleRequest
* (com.raytheon.uf.common.serialization.comm.IServerRequest)
*/
@Override
public Object handleRequest(TextDBRequest request) throws Exception {
return textdbSrv.processMessage(request.getMessage());
}
}

View file

@ -1,176 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
*/
package com.raytheon.uf.edex.plugin.text.dbsrv;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import com.raytheon.uf.common.message.Message;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.util.ITimer;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.util.ByteArrayOutputStreamPool;
import com.raytheon.uf.common.util.SizeUtil;
import com.raytheon.uf.common.util.stream.LimitingInputStream;
import com.raytheon.uf.common.util.stream.LimitingOutputStream;
import com.raytheon.uf.edex.plugin.text.dbsrv.impl.CommandExecutor;
/**
* Thin wrapper around TextDBSrv to handle marshalling/unmarshalling and
* limiting of the byte stream.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 15, 2014 2928 rjpeter Initial creation.
* May 15, 2014 2536 bclement moved from uf.edex.textdbsrv
*
* </pre>
*
* @author rjpeter
* @version 1.0
*/
public class TextDBSrvWrapper {
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(TextDBSrvWrapper.class);
private static final IUFStatusHandler textDbSrvLogger = UFStatus
.getNamedHandler("TextDBSrvRequestLogger");
/**
* The limit of bytes that we are able to read in without erroring off.
*/
private long byteLimitInMB;
/**
* TextDbSrv implementation to use.
*/
private TextDBSrv textdbSrv;
/**
* Unmarshalls the input stream as xml data and sends to textdbsrv for
* processing.
*
* @param is
* @return
*/
public byte[] executeTextDBMessage(InputStream xmlDataStream) {
ITimer timer = TimeUtil.getTimer();
timer.start();
/*
* This stream does not need to be closed, Camel will handle closing of
* data
*/
LimitingInputStream inputStream = null;
String sizeString = null;
Message rval;
try {
inputStream = new LimitingInputStream(xmlDataStream, byteLimitInMB
* SizeUtil.BYTES_PER_MB);
Message message = SerializationUtil.jaxbUnmarshalFromInputStream(
Message.class, inputStream);
sizeString = SizeUtil.prettyByteSize(inputStream.getBytesRead());
textDbSrvLogger.info("Processing xml message of length: "
+ sizeString);
rval = textdbSrv.processMessage(message);
} catch (Throwable e) {
statusHandler
.error("Error occured processing textDbSrv message", e);
rval = CommandExecutor
.createErrorMessage("Error occurred during processing: "
+ e.getLocalizedMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// ignore
}
}
}
LimitingOutputStream outStream = null;
int tries = 0;
byte[] bytesOut = null;
while ((bytesOut == null) && (tries < 2)) {
try {
ByteArrayOutputStream baos = ByteArrayOutputStreamPool
.getInstance().getStream();
outStream = new LimitingOutputStream(baos, byteLimitInMB
* SizeUtil.BYTES_PER_MB);
SerializationUtil.jaxbMarshalToStream(rval, outStream);
bytesOut = baos.toByteArray();
} catch (Exception e) {
statusHandler.error("Error occured marshalling response", e);
tries++;
rval = CommandExecutor
.createErrorMessage("Error occurred during processing: "
+ e.getLocalizedMessage());
} finally {
if (outStream != null) {
try {
outStream.close();
} catch (IOException e) {
// ignore
}
}
}
}
timer.stop();
StringBuilder sb = new StringBuilder(300);
sb.append("Processed message in ").append(timer.getElapsedTime())
.append("ms, ");
sb.append("request was size ").append(sizeString);
sb.append(", response was size ")
.append(SizeUtil
.prettyByteSize(bytesOut != null ? bytesOut.length : 0));
textDbSrvLogger.info(sb.toString());
return bytesOut;
}
public long getByteLimitInMB() {
return byteLimitInMB;
}
public void setByteLimitInMB(long byteLimitInMB) {
this.byteLimitInMB = byteLimitInMB;
}
public TextDBSrv getTextdbSrv() {
return textdbSrv;
}
public void setTextdbSrv(TextDBSrv textdbSrv) {
this.textdbSrv = textdbSrv;
}
}

View file

@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor; import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor;
import com.raytheon.uf.common.dataplugin.text.dbsrv.PropConverter;
import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags;
import com.raytheon.uf.common.message.Header; import com.raytheon.uf.common.message.Header;
import com.raytheon.uf.common.message.Message; import com.raytheon.uf.common.message.Message;
@ -41,6 +40,7 @@ import com.raytheon.uf.common.message.Property;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Oct 7, 2008 1538 jkorman Initial creation * Oct 7, 2008 1538 jkorman Initial creation
* May 15, 2014 2536 bclement moved from uf.edex.textdbsrv, removed unused logger * May 15, 2014 2536 bclement moved from uf.edex.textdbsrv, removed unused logger
* Aug 22, 2014 2926 bclement compatibility changes with new textdb service
* *
* </pre> * </pre>
* *
@ -50,6 +50,10 @@ import com.raytheon.uf.common.message.Property;
public class CommandExecutor implements ICommandExecutor { public class CommandExecutor implements ICommandExecutor {
protected static final String STDERR = "STDERR";
protected static final String STDOUT = "STDOUT";
private static final TextDBSrvCommandTags VIEW_CMD = TextDBSrvCommandTags.VIEW; private static final TextDBSrvCommandTags VIEW_CMD = TextDBSrvCommandTags.VIEW;
private Map<String, ICommandExecutor> execMap = new HashMap<String, ICommandExecutor>(); private Map<String, ICommandExecutor> execMap = new HashMap<String, ICommandExecutor>();
@ -96,7 +100,7 @@ public class CommandExecutor implements ICommandExecutor {
if (message != null) { if (message != null) {
Header header = message.getHeader(); Header header = message.getHeader();
if (header != null) { if (header != null) {
cmdView = PropConverter.getProperty(header, VIEW_CMD.name()); cmdView = header.getProperty(VIEW_CMD.name());
} }
} }
return cmdView; return cmdView;
@ -135,8 +139,7 @@ public class CommandExecutor implements ICommandExecutor {
public static final Message createErrorMessage(String error) { public static final Message createErrorMessage(String error) {
Message msg = new Message(); Message msg = new Message();
Header h = new Header(); Header h = new Header();
h.setProperties(new Property[] { new Property("STDERR", PropConverter h.setProperties(new Property[] { new Property(STDERR, error), });
.asciiToHex(error)), });
msg.setHeader(h); msg.setHeader(h);

View file

@ -24,7 +24,6 @@ import java.util.List;
import com.raytheon.uf.common.dataplugin.text.db.StateMatch; import com.raytheon.uf.common.dataplugin.text.db.StateMatch;
import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor; import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor;
import com.raytheon.uf.common.dataplugin.text.dbsrv.PropConverter;
import com.raytheon.uf.common.dataplugin.text.dbsrv.StateTableTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.StateTableTags;
import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags;
import com.raytheon.uf.common.message.Header; import com.raytheon.uf.common.message.Header;
@ -42,6 +41,7 @@ import com.raytheon.uf.edex.plugin.text.db.TextDB;
* Oct 7, 2008 1538 jkorman Initial creation * Oct 7, 2008 1538 jkorman Initial creation
* Aug 31, 2010 2103 cjeanbap Check variable for null. * Aug 31, 2010 2103 cjeanbap Check variable for null.
* May 15, 2014 2536 bclement moved from uf.edex.textdbsrv * May 15, 2014 2536 bclement moved from uf.edex.textdbsrv
* Aug 22, 2014 2926 bclement compatibility changes with new textdb service
* *
* </pre> * </pre>
* *
@ -86,8 +86,7 @@ public class StateTableAdapter implements ICommandExecutor {
Header sHeader = cmdMessage.getHeader(); Header sHeader = cmdMessage.getHeader();
// Get the operation code // Get the operation code
String op = PropConverter String op = sHeader.getProperty(StateTableTags.OP.name());
.getProperty(sHeader, StateTableTags.OP.name());
TextDBSrvCommandTags opTag = TextDBSrvCommandTags.valueOf(op); TextDBSrvCommandTags opTag = TextDBSrvCommandTags.valueOf(op);
@ -95,32 +94,25 @@ public class StateTableAdapter implements ICommandExecutor {
switch (opTag) { switch (opTag) {
case PUT: { case PUT: {
String state = PropConverter.getProperty(sHeader, String state = sHeader.getProperty(StateTableTags.STATE.name());
StateTableTags.STATE.name()); String cccId = sHeader.getProperty(StateTableTags.CCC.name());
String cccId = PropConverter.getProperty(sHeader, String xxxId = sHeader.getProperty(StateTableTags.XXX.name());
StateTableTags.CCC.name());
String xxxId = PropConverter.getProperty(sHeader,
StateTableTags.XXX.name());
if ((state != null) && (cccId != null) && (xxxId != null)) { if ((state != null) && (cccId != null) && (xxxId != null)) {
addStateData(sHeader, state, xxxId, cccId); addStateData(sHeader, state, xxxId, cccId);
} }
break; break;
} }
case GET: { case GET: {
String state = PropConverter.getProperty(sHeader, String state = sHeader.getProperty(StateTableTags.STATE.name());
StateTableTags.STATE.name());
if (state != null) { if (state != null) {
getStateData(sHeader, state); getStateData(sHeader, state);
} }
break; break;
} }
case DELETE: { case DELETE: {
String state = PropConverter.getProperty(sHeader, String state = sHeader.getProperty(StateTableTags.STATE.name());
StateTableTags.STATE.name()); String cccId = sHeader.getProperty(StateTableTags.CCC.name());
String cccId = PropConverter.getProperty(sHeader, String xxxId = sHeader.getProperty(StateTableTags.XXX.name());
StateTableTags.CCC.name());
String xxxId = PropConverter.getProperty(sHeader,
StateTableTags.XXX.name());
if ((state != null) && (cccId != null) && (xxxId != null)) { if ((state != null) && (cccId != null) && (xxxId != null)) {
deleteStateData(sHeader, state, xxxId, cccId); deleteStateData(sHeader, state, xxxId, cccId);
} }
@ -128,10 +120,9 @@ public class StateTableAdapter implements ICommandExecutor {
} }
default: { default: {
String tagName = (opTag != null) ? opTag.name() : "null"; String tagName = (opTag != null) ? opTag.name() : "null";
Property[] props = new Property[] { new Property("STDERR", Property[] props = new Property[] { new Property(
PropConverter CommandExecutor.STDERR,
.asciiToHex("ERROR:Invalid command tag = [" "ERROR:Invalid command tag = [" + tagName + "]"), };
+ tagName + "]")), };
sHeader.setProperties(props); sHeader.setProperties(props);
break; break;
} }
@ -152,11 +143,10 @@ public class StateTableAdapter implements ICommandExecutor {
*/ */
private void addStateData(Header header, String state, String xxxId, private void addStateData(Header header, String state, String xxxId,
String cccId) { String cccId) {
Property newProperty = new Property("STDERR", Property newProperty = new Property(CommandExecutor.STDERR,
PropConverter.asciiToHex("NORMAL:Adding a new state-ccc.")); "NORMAL:Adding a new state-ccc.");
Property errProperty = new Property("STDERR", Property errProperty = new Property(CommandExecutor.STDERR,
PropConverter "ERROR:Failure adding to state_ccc table.");
.asciiToHex("ERROR:Failure adding to state_ccc table."));
Property[] props = new Property[] { newProperty, }; Property[] props = new Property[] { newProperty, };
if (!textDB.addState(state, cccId, xxxId)) { if (!textDB.addState(state, cccId, xxxId)) {
@ -175,7 +165,7 @@ public class StateTableAdapter implements ICommandExecutor {
private void getStateData(Header header, String state) { private void getStateData(Header header, String state) {
final int HEADER_LINES = 2; final int HEADER_LINES = 2;
String PROP_FMT = "STDOUT"; String PROP_FMT = CommandExecutor.STDOUT;
Property[] props = null; Property[] props = null;
@ -184,20 +174,15 @@ public class StateTableAdapter implements ICommandExecutor {
if (dataList != null && dataList.size() > 0) { if (dataList != null && dataList.size() > 0) {
props = new Property[dataList.size() + HEADER_LINES]; props = new Property[dataList.size() + HEADER_LINES];
int i = 0; int i = 0;
props[i++] = new Property(PROP_FMT, props[i++] = new Property(PROP_FMT, "XXX CCC");
PropConverter.asciiToHex("XXX CCC")); props[i++] = new Property(PROP_FMT, "-------");
props[i++] = new Property(PROP_FMT,
PropConverter.asciiToHex("-------"));
for (StateMatch s : dataList) { for (StateMatch s : dataList) {
props[i++] = new Property(PROP_FMT, PropConverter.asciiToHex(s props[i++] = new Property(PROP_FMT, s.getPk().getXxx() + " "
.getPk() + s.getPk().getCcc());
.getXxx() + " " + s.getPk().getCcc()));
} }
} else { } else {
props = new Property[] { new Property( props = new Property[] { new Property(CommandExecutor.STDERR,
"STDERR", "ERROR:Failure reading from state lookup table."), };
PropConverter
.asciiToHex("ERROR:Failure reading from state lookup table.")), };
} }
header.setProperties(props); header.setProperties(props);
} }
@ -215,12 +200,11 @@ public class StateTableAdapter implements ICommandExecutor {
Property[] props = null; Property[] props = null;
if (textDB.removeState(state, xxxId, cccId)) { if (textDB.removeState(state, xxxId, cccId)) {
props = new Property[] { new Property("STDERR", props = new Property[] { new Property(CommandExecutor.STDERR,
PropConverter.asciiToHex("NORMAL:Deleting state-ccc.")), }; "NORMAL:Deleting state-ccc."), };
} else { } else {
props = new Property[] { new Property("STDERR", props = new Property[] { new Property(CommandExecutor.STDERR,
PropConverter "ERROR:Failure deleting from state_ccc table."), };
.asciiToHex("ERROR:Failure deleting from state_ccc table.")), };
} }
header.setProperties(props); header.setProperties(props);
} }

View file

@ -35,7 +35,6 @@ import org.apache.commons.logging.LogFactory;
import com.raytheon.uf.common.dataplugin.text.db.StdTextProduct; import com.raytheon.uf.common.dataplugin.text.db.StdTextProduct;
import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor; import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor;
import com.raytheon.uf.common.dataplugin.text.dbsrv.PropConverter;
import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags;
import com.raytheon.uf.common.dataplugin.text.dbsrv.TextViewGetTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.TextViewGetTags;
import com.raytheon.uf.common.dataplugin.text.dbsrv.TextViewTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.TextViewTags;
@ -74,6 +73,7 @@ import com.raytheon.uf.edex.plugin.text.db.TextDB;
* 27Apr2012 564 jkorman Added sort to ALL times retrieval. * 27Apr2012 564 jkorman Added sort to ALL times retrieval.
* May 15, 2014 2536 bclement moved from uf.edex.textdbsrv, added marshalToStream() * May 15, 2014 2536 bclement moved from uf.edex.textdbsrv, added marshalToStream()
* Jul 15, 2014 3373 bclement jaxb manager api changes * Jul 15, 2014 3373 bclement jaxb manager api changes
* Aug 22, 2014 2926 bclement compatibility changes with new textdb service
* *
* </pre> * </pre>
* *
@ -82,6 +82,7 @@ import com.raytheon.uf.edex.plugin.text.db.TextDB;
*/ */
public class TextViewAdapter implements ICommandExecutor { public class TextViewAdapter implements ICommandExecutor {
// This is the default textdb formatted time. // This is the default textdb formatted time.
// Oct 31 08 10:13:15 GMT // Oct 31 08 10:13:15 GMT
private static final String DEFAULT_TIME_FORMAT = "%1$tb %1$td %1$ty %1$tT GMT"; private static final String DEFAULT_TIME_FORMAT = "%1$tb %1$td %1$ty %1$tT GMT";
@ -130,7 +131,7 @@ public class TextViewAdapter implements ICommandExecutor {
Header sHeader = cmdMessage.getHeader(); Header sHeader = cmdMessage.getHeader();
// Get the operation code // Get the operation code
String op = PropConverter.getProperty(sHeader, TextViewTags.OP.name()); String op = sHeader.getProperty(TextViewTags.OP.name());
TextDBSrvCommandTags opTag = TextDBSrvCommandTags.valueOf(op); TextDBSrvCommandTags opTag = TextDBSrvCommandTags.valueOf(op);
@ -147,18 +148,17 @@ public class TextViewAdapter implements ICommandExecutor {
break; break;
} }
case DELETE: { case DELETE: {
Property[] props = new Property[] { new Property("STDERR", Property[] props = new Property[] { new Property(
PropConverter.asciiToHex("ERROR:Command tag = [" CommandExecutor.STDERR,
+ opTag.name() "ERROR:Command tag = [" + opTag.name()
+ "] not implemented")), }; + "] not implemented"), };
sHeader.setProperties(props); sHeader.setProperties(props);
break; break;
} }
default: { default: {
Property[] props = new Property[] { new Property("STDERR", Property[] props = new Property[] { new Property(
PropConverter CommandExecutor.STDERR,
.asciiToHex("ERROR:Invalid command tag = [" "ERROR:Invalid command tag = [" + op + "]"), };
+ op + "]")), };
sHeader.setProperties(props); sHeader.setProperties(props);
break; break;
} }
@ -183,12 +183,9 @@ public class TextViewAdapter implements ICommandExecutor {
* @return the updated message header * @return the updated message header
*/ */
private Header processPutRequest(Header msgHeader) { private Header processPutRequest(Header msgHeader) {
String prodId = PropConverter.getProperty(msgHeader, String prodId = msgHeader.getProperty(TextViewTags.PRODID.name());
TextViewTags.PRODID.name()); String product = msgHeader.getProperty(TextViewTags.PRODUCT.name());
String product = PropConverter.getProperty(msgHeader, String strMode = msgHeader.getProperty(TextViewTags.OPERATIONAL.name());
TextViewTags.PRODUCT.name());
String strMode = PropConverter.getProperty(msgHeader,
TextViewTags.OPERATIONAL.name());
boolean operationalMode = isOperationalMode(strMode); boolean operationalMode = isOperationalMode(strMode);
long insertTime = textDB.writeProduct(prodId, product, operationalMode, long insertTime = textDB.writeProduct(prodId, product, operationalMode,
@ -201,14 +198,14 @@ public class TextViewAdapter implements ICommandExecutor {
Date d = new Date(); Date d = new Date();
d.setTime(insertTime); d.setTime(insertTime);
AlarmAlertUtil.sendProductAlarmAlert(prodId, d, operationalMode); AlarmAlertUtil.sendProductAlarmAlert(prodId, d, operationalMode);
Property[] props = new Property[] { new Property("STDERR", Property[] props = new Property[] { new Property(
PropConverter.asciiToHex("NORMAL:Saved " + prodId)), }; CommandExecutor.STDERR,
"NORMAL:Saved " + prodId), };
msgHeader.setProperties(props); msgHeader.setProperties(props);
} else { } else {
Property[] props = new Property[] { new Property("STDERR", Property[] props = new Property[] { new Property(
PropConverter CommandExecutor.STDERR,
.asciiToHex("NORMAL:Not Saved; duplicate product " "NORMAL:Not Saved; duplicate product " + prodId), };
+ prodId)), };
msgHeader.setProperties(props); msgHeader.setProperties(props);
} }
@ -222,31 +219,28 @@ public class TextViewAdapter implements ICommandExecutor {
*/ */
private Header processGetRequest(Header msgHeader) { private Header processGetRequest(Header msgHeader) {
String op = PropConverter.getProperty(msgHeader, String op = msgHeader.getProperty(TextViewTags.SUBOP.name());
TextViewTags.SUBOP.name());
TextViewGetTags subOp = TextViewGetTags.valueOf(op); TextViewGetTags subOp = TextViewGetTags.valueOf(op);
boolean operationalMode = isOperationalMode(PropConverter.getProperty( boolean operationalMode = isOperationalMode(msgHeader
msgHeader, .getProperty(TextViewTags.OPERATIONAL.name()));
TextViewTags.OPERATIONAL.name()));
if (subOp != null) { if (subOp != null) {
if (TextViewGetTags.LATEST.equals(subOp)) { if (TextViewGetTags.LATEST.equals(subOp)) {
List<Long> times = new ArrayList<Long>(); List<Long> times = new ArrayList<Long>();
String fmtType = PropConverter.getProperty(msgHeader, String fmtType = msgHeader.getProperty(TextViewTags.FORMAT
TextViewTags.FORMAT.name()); .name());
String timeFmt = PropConverter.getProperty(msgHeader, String timeFmt = msgHeader.getProperty(TextViewTags.CLIENTFMT
TextViewTags.CLIENTFMT.name()); .name());
// get the latest time for one or more products. // get the latest time for one or more products.
Property[] msgProps = msgHeader.getProperties(); Property[] msgProps = msgHeader.getProperties();
for (Property p : msgProps) { for (Property p : msgProps) {
if (TextViewTags.PRODID.name().equals(p.getName())) { if (TextViewTags.PRODID.name().equals(p.getName())) {
times.add(textDB.getLatestTime( times.add(textDB.getLatestTime(p.getValue(),
PropConverter.hexToAscii(p.getValue()),
operationalMode)); operationalMode));
} }
} // for } // for
@ -254,18 +248,17 @@ public class TextViewAdapter implements ICommandExecutor {
int pIndex = 0; int pIndex = 0;
for (Long t : times) { for (Long t : times) {
String s = formatTime(t, fmtType, timeFmt); String s = formatTime(t, fmtType, timeFmt);
msgProps[pIndex++] = new Property("STDOUT", msgProps[pIndex++] = new Property(CommandExecutor.STDOUT, s);
PropConverter.asciiToHex(s));
} }
msgHeader.setProperties(msgProps); msgHeader.setProperties(msgProps);
} else if (TextViewGetTags.ALL.equals(subOp)) { } else if (TextViewGetTags.ALL.equals(subOp)) {
// get all times for a product // get all times for a product
String productId = PropConverter.getProperty(msgHeader, String productId = msgHeader.getProperty(TextViewTags.PRODID
TextViewTags.PRODID.name()); .name());
String fmtType = PropConverter.getProperty(msgHeader, String fmtType = msgHeader.getProperty(TextViewTags.FORMAT
TextViewTags.FORMAT.name()); .name());
String timeFmt = PropConverter.getProperty(msgHeader, String timeFmt = msgHeader.getProperty(TextViewTags.CLIENTFMT
TextViewTags.CLIENTFMT.name()); .name());
List<Long> times = textDB.getAllTimes(productId, List<Long> times = textDB.getAllTimes(productId,
operationalMode); operationalMode);
@ -276,21 +269,20 @@ public class TextViewAdapter implements ICommandExecutor {
int pIndex = 0; int pIndex = 0;
for (Long t : times) { for (Long t : times) {
String s = formatTime(t, fmtType, timeFmt); String s = formatTime(t, fmtType, timeFmt);
msgProps[pIndex++] = new Property("STDOUT", msgProps[pIndex++] = new Property(CommandExecutor.STDOUT, s);
PropConverter.asciiToHex(s));
} }
msgHeader.setProperties(msgProps); msgHeader.setProperties(msgProps);
} else if (TextViewGetTags.INFO.equals(subOp) } else if (TextViewGetTags.INFO.equals(subOp)
|| TextViewGetTags.PROD.equals(subOp) || TextViewGetTags.PROD.equals(subOp)
|| TextViewGetTags.PRODXML.equals(subOp)) { || TextViewGetTags.PRODXML.equals(subOp)) {
String siteCCCNNNXX = PropConverter.getProperty(msgHeader, String siteCCCNNNXX = msgHeader.getProperty(TextViewTags.SITE
TextViewTags.SITE.name()); .name());
if (siteCCCNNNXX == null) { if (siteCCCNNNXX == null) {
boolean infoFlag = TextViewGetTags.INFO.equals(subOp); boolean infoFlag = TextViewGetTags.INFO.equals(subOp);
boolean xmlFlag = TextViewGetTags.PRODXML.equals(subOp); boolean xmlFlag = TextViewGetTags.PRODXML.equals(subOp);
String afosCmd = PropConverter.getProperty(msgHeader, String afosCmd = msgHeader.getProperty(TextViewTags.AFOSCMD
TextViewTags.AFOSCMD.name()); .name());
logger.info("AFOS Command = " + afosCmd); logger.info("AFOS Command = " + afosCmd);
@ -302,8 +294,7 @@ public class TextViewAdapter implements ICommandExecutor {
if (infoFlag) { if (infoFlag) {
String ss = "********** Product Count = " String ss = "********** Product Count = "
+ prods.size(); + prods.size();
prodList.add(new Property("STDOUT", PropConverter prodList.add(new Property(CommandExecutor.STDOUT, ss));
.asciiToHex(ss)));
} }
try { try {
@ -311,21 +302,20 @@ public class TextViewAdapter implements ICommandExecutor {
if (xmlFlag) { if (xmlFlag) {
ByteArrayOutputStream strm = new ByteArrayOutputStream(); ByteArrayOutputStream strm = new ByteArrayOutputStream();
marshalToStream(prod, strm); marshalToStream(prod, strm);
prodList.add(new Property("STDOUT", prodList.add(new Property(
PropConverter.asciiToHex(strm CommandExecutor.STDOUT, strm.toString()));
.toString())));
} else { } else {
String s = prod.getProduct(); String s = prod.getProduct();
if (s != null) { if (s != null) {
if (infoFlag) { if (infoFlag) {
String ss = "********** Product Size = " String ss = "********** Product Size = "
+ s.length(); + s.length();
prodList.add(new Property("STDOUT", prodList.add(new Property(
PropConverter.asciiToHex(ss))); CommandExecutor.STDOUT, ss));
} }
prodList.add(new Property("STDOUT", prodList.add(new Property(
PropConverter.asciiToHex(s))); CommandExecutor.STDOUT, s));
} }
} }
} }
@ -342,11 +332,11 @@ public class TextViewAdapter implements ICommandExecutor {
Property[] props = new Property[1]; Property[] props = new Property[1];
if (cccNNNXXX != null) { if (cccNNNXXX != null) {
props[0] = new Property("STDOUT", props[0] = new Property(CommandExecutor.STDOUT,
PropConverter.asciiToHex(cccNNNXXX)); cccNNNXXX);
} else { } else {
props[0] = new Property("STDERR", props[0] = new Property(CommandExecutor.STDERR,
PropConverter.asciiToHex(UNKNOWN_SITE)); UNKNOWN_SITE);
} }
msgHeader.setProperties(props); msgHeader.setProperties(props);
@ -356,20 +346,17 @@ public class TextViewAdapter implements ICommandExecutor {
boolean xmlFlag = TextViewGetTags.JOINXML.equals(subOp); boolean xmlFlag = TextViewGetTags.JOINXML.equals(subOp);
// get all times for a product // get all times for a product
String wmoId = PropConverter.getProperty(msgHeader, String wmoId = msgHeader.getProperty(TextViewTags.WMOID.name());
TextViewTags.WMOID.name()); String site = msgHeader.getProperty(TextViewTags.SITE.name());
String site = PropConverter.getProperty(msgHeader, String abbrId = msgHeader.getProperty(TextViewTags.NNNXXX
TextViewTags.SITE.name()); .name());
String abbrId = PropConverter.getProperty(msgHeader, String lastHrs = msgHeader
TextViewTags.NNNXXX.name()); .getProperty(TextViewTags.HOUR.name());
String lastHrs = PropConverter.getProperty(msgHeader, String hdrTime = msgHeader.getProperty(TextViewTags.HDRTIME
TextViewTags.HOUR.name()); .name());
String hdrTime = PropConverter.getProperty(msgHeader, String bbbId = msgHeader.getProperty(TextViewTags.BBB.name());
TextViewTags.HDRTIME.name()); String fullDataReadProp = msgHeader
String bbbId = PropConverter.getProperty(msgHeader, .getProperty(TextViewTags.FULLREAD.name());
TextViewTags.BBB.name());
String fullDataReadProp = PropConverter.getProperty(msgHeader,
TextViewTags.FULLREAD.name());
boolean fullDataRead = false; boolean fullDataRead = false;
if (fullDataReadProp != null && fullDataReadProp.length() > 0) { if (fullDataReadProp != null && fullDataReadProp.length() > 0) {
@ -387,9 +374,8 @@ public class TextViewAdapter implements ICommandExecutor {
// if not xml or last hours request, add the number of returned // if not xml or last hours request, add the number of returned
// items // items
if (!xmlFlag && (lastHrs == null || lastHrs.length() == 0)) { if (!xmlFlag && (lastHrs == null || lastHrs.length() == 0)) {
prodList.add(new Property("STDOUT", PropConverter prodList.add(new Property(CommandExecutor.STDOUT, ""
.asciiToHex("" + prods.size()));
+ prods.size())));
} }
StringBuilder header = new StringBuilder(); StringBuilder header = new StringBuilder();
@ -400,9 +386,8 @@ public class TextViewAdapter implements ICommandExecutor {
if (xmlFlag) { if (xmlFlag) {
ByteArrayOutputStream strm = new ByteArrayOutputStream(); ByteArrayOutputStream strm = new ByteArrayOutputStream();
marshalToStream(prod, strm); marshalToStream(prod, strm);
prodList.add(new Property("STDOUT", PropConverter prodList.add(new Property(CommandExecutor.STDOUT,
.asciiToHex(strm strm.toString()));
.toString())));
} else { } else {
String cccId = prod.getCccid(); String cccId = prod.getCccid();
String nnnId = prod.getNnnid(); String nnnId = prod.getNnnid();
@ -427,8 +412,9 @@ public class TextViewAdapter implements ICommandExecutor {
header.append(cccId); header.append(cccId);
header.append(nnnId); header.append(nnnId);
header.append(xxxId); header.append(xxxId);
prodList.add(new Property("STDOUT", PropConverter prodList.add(new Property(CommandExecutor.STDOUT,
.asciiToHex(header.toString()))); header
.toString()));
} }
} }
} catch (SerializationException e) { } catch (SerializationException e) {

View file

@ -21,7 +21,6 @@ package com.raytheon.uf.edex.plugin.text.dbsrv.impl;
import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor; import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor;
import com.raytheon.uf.common.dataplugin.text.dbsrv.PropConverter;
import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags;
import com.raytheon.uf.common.dataplugin.text.dbsrv.VersionsTableTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.VersionsTableTags;
import com.raytheon.uf.common.message.Header; import com.raytheon.uf.common.message.Header;
@ -40,6 +39,7 @@ import com.raytheon.uf.edex.plugin.text.db.TextDB;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Oct 8, 2008 1538 jkorman Initial creation * Oct 8, 2008 1538 jkorman Initial creation
* May 15, 2014 2536 bclement moved from uf.edex.textdbsrv * May 15, 2014 2536 bclement moved from uf.edex.textdbsrv
* Aug 22, 2014 2926 bclement compatibility changes with new textdb service
* *
* </pre> * </pre>
* *
@ -81,12 +81,10 @@ public class VersionsAdapter implements ICommandExecutor {
Header sHeader = cmdMessage.getHeader(); Header sHeader = cmdMessage.getHeader();
// Get the operation code // Get the operation code
String op = PropConverter.getProperty(sHeader, String op = sHeader.getProperty(VersionsTableTags.OP.name());
VersionsTableTags.OP.name());
TextDBSrvCommandTags opTag = TextDBSrvCommandTags.valueOf(op); TextDBSrvCommandTags opTag = TextDBSrvCommandTags.valueOf(op);
String productId = PropConverter.getProperty(sHeader, String productId = sHeader.getProperty(VersionsTableTags.PRODID.name());
VersionsTableTags.PRODID.name());
if (opTag != null && productId != null) { if (opTag != null && productId != null) {
AFOSProductId prodId = new AFOSProductId(productId); AFOSProductId prodId = new AFOSProductId(productId);
@ -94,8 +92,7 @@ public class VersionsAdapter implements ICommandExecutor {
switch (opTag) { switch (opTag) {
case PUT: { case PUT: {
String versions = PropConverter.getProperty(sHeader, String versions = sHeader.getProperty(VersionsTableTags.VERSION.name());
VersionsTableTags.VERSION.name());
addVersionInfo(sHeader, prodId.getCcc(), prodId.getNnn(), addVersionInfo(sHeader, prodId.getCcc(), prodId.getNnn(),
prodId.getXxx(), versions); prodId.getXxx(), versions);
@ -114,10 +111,9 @@ public class VersionsAdapter implements ICommandExecutor {
} }
default: { default: {
String tagName = (opTag != null) ? opTag.name() : "null"; String tagName = (opTag != null) ? opTag.name() : "null";
Property[] props = new Property[] { new Property("STDERR", Property[] props = new Property[] { new Property(
PropConverter CommandExecutor.STDERR,
.asciiToHex("ERROR:Invalid command tag = [" "ERROR:Invalid command tag = [" + tagName + "]"), };
+ tagName + "]")), };
sHeader.setProperties(props); sHeader.setProperties(props);
break; break;
} }
@ -140,12 +136,11 @@ public class VersionsAdapter implements ICommandExecutor {
*/ */
private void addVersionInfo(Header header, String ccc, String nnn, private void addVersionInfo(Header header, String ccc, String nnn,
String xxx, String versions) { String xxx, String versions) {
Property newProperty = new Property("STDERR", Property newProperty = new Property(CommandExecutor.STDERR,
PropConverter.asciiToHex("NORMAL:Adding productId " + ccc + nnn "NORMAL:Adding productId " + ccc + nnn + xxx + " versions "
+ xxx + " versions " + versions)); + versions);
Property errProperty = new Property("STDERR", Property errProperty = new Property(CommandExecutor.STDERR,
PropConverter "ERROR:Failure adding to versions table.");
.asciiToHex("ERROR:Failure adding to versions table."));
Property[] props = new Property[] { newProperty, }; Property[] props = new Property[] { newProperty, };
if (!textDB.addVersions(ccc, nnn, xxx, Integer.parseInt(versions))) { if (!textDB.addVersions(ccc, nnn, xxx, Integer.parseInt(versions))) {
@ -163,19 +158,16 @@ public class VersionsAdapter implements ICommandExecutor {
*/ */
private void getVersionInfo(Header header, String ccc, String nnn, private void getVersionInfo(Header header, String ccc, String nnn,
String xxx) { String xxx) {
String PROP_FMT = "STDOUT"; String PROP_FMT = CommandExecutor.STDOUT;
Property[] props = null; Property[] props = null;
String vers = textDB.getVersions(ccc, nnn, xxx); String vers = textDB.getVersions(ccc, nnn, xxx);
if (vers != null) { if (vers != null) {
props = new Property[] { new Property(PROP_FMT, props = new Property[] { new Property(PROP_FMT, vers) };
PropConverter.asciiToHex(vers)) };
} else { } else {
props = new Property[] { new Property( props = new Property[] { new Property(CommandExecutor.STDERR,
"STDERR", "ERROR:Failure reading versions table."), };
PropConverter
.asciiToHex("ERROR:Failure reading versions table.")), };
} }
header.setProperties(props); header.setProperties(props);
} }
@ -189,12 +181,12 @@ public class VersionsAdapter implements ICommandExecutor {
*/ */
private void deleteVersionInfo(Header header, String ccc, String nnn, private void deleteVersionInfo(Header header, String ccc, String nnn,
String xxx) { String xxx) {
Property newProperty = new Property("STDERR", Property newProperty = new Property(CommandExecutor.STDERR,
PropConverter.asciiToHex("NORMAL:Deleting product id " + ccc "NORMAL:Deleting product id " + ccc + nnn + xxx
+ nnn + xxx + " from versionstable.")); + " from versionstable.");
Property errProperty = new Property("STDERR", Property errProperty = new Property(CommandExecutor.STDERR,
PropConverter.asciiToHex("ERROR:Failure deleting " + ccc + nnn "ERROR:Failure deleting "
+ xxx + " from versionstable.")); + ccc + nnn + xxx + " from versionstable.");
Property[] props = new Property[] { newProperty, }; Property[] props = new Property[] { newProperty, };
if (!textDB.deleteVersions(ccc, nnn, xxx)) { if (!textDB.deleteVersions(ccc, nnn, xxx)) {

View file

@ -28,7 +28,6 @@ import org.apache.commons.logging.LogFactory;
import com.raytheon.uf.common.dataplugin.text.db.WatchWarn; import com.raytheon.uf.common.dataplugin.text.db.WatchWarn;
import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor; import com.raytheon.uf.common.dataplugin.text.dbsrv.ICommandExecutor;
import com.raytheon.uf.common.dataplugin.text.dbsrv.PropConverter;
import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.TextDBSrvCommandTags;
import com.raytheon.uf.common.dataplugin.text.dbsrv.WarnTableTags; import com.raytheon.uf.common.dataplugin.text.dbsrv.WarnTableTags;
import com.raytheon.uf.common.message.Header; import com.raytheon.uf.common.message.Header;
@ -50,6 +49,7 @@ import com.raytheon.uf.edex.plugin.text.db.TextDB;
* from WatchWarn table. * from WatchWarn table.
* Sep 14,2010 3944 cjenabap Added sendTextToQueue() * Sep 14,2010 3944 cjenabap Added sendTextToQueue()
* May 15, 2014 2536 bclement moved from uf.edex.textdbsrv * May 15, 2014 2536 bclement moved from uf.edex.textdbsrv
* Aug 22, 2014 2926 bclement compatibility changes with new textdb service
* </pre> * </pre>
* *
* @author jkorman * @author jkorman
@ -94,7 +94,7 @@ public class WarnTableAdapter implements ICommandExecutor {
Header sHeader = cmdMessage.getHeader(); Header sHeader = cmdMessage.getHeader();
// Get the operation code // Get the operation code
String op = PropConverter.getProperty(sHeader, WarnTableTags.OP.name()); String op = sHeader.getProperty(WarnTableTags.OP.name());
TextDBSrvCommandTags opTag = TextDBSrvCommandTags.valueOf(op); TextDBSrvCommandTags opTag = TextDBSrvCommandTags.valueOf(op);
@ -102,10 +102,8 @@ public class WarnTableAdapter implements ICommandExecutor {
switch (opTag) { switch (opTag) {
case PUT: { case PUT: {
String productId = PropConverter.getProperty(sHeader, String productId = sHeader.getProperty(WarnTableTags.PRODID.name());
WarnTableTags.PRODID.name()); String script = sHeader.getProperty(WarnTableTags.SCRIPT.name());
String script = PropConverter.getProperty(sHeader,
WarnTableTags.SCRIPT.name());
addWatchWarn(sHeader, productId, script); addWatchWarn(sHeader, productId, script);
sendTextToQueue(productId, WATCH_WARN_QUEUE); sendTextToQueue(productId, WATCH_WARN_QUEUE);
@ -113,18 +111,15 @@ public class WarnTableAdapter implements ICommandExecutor {
} }
case GET: { case GET: {
String productId = PropConverter.getProperty(sHeader, String productId = sHeader.getProperty(WarnTableTags.PRODID.name());
WarnTableTags.PRODID.name());
if (productId != null) { if (productId != null) {
getWatchWarn(sHeader, productId); getWatchWarn(sHeader, productId);
} }
break; break;
} }
case DELETE: { case DELETE: {
String productId = PropConverter.getProperty(sHeader, String productId = sHeader.getProperty(WarnTableTags.PRODID.name());
WarnTableTags.PRODID.name()); String script = sHeader.getProperty(WarnTableTags.SCRIPT.name());
String script = PropConverter.getProperty(sHeader,
WarnTableTags.SCRIPT.name());
if ((productId != null) && (script != null)) { if ((productId != null) && (script != null)) {
deleteWatchWarn(sHeader, productId, script); deleteWatchWarn(sHeader, productId, script);
@ -142,9 +137,9 @@ public class WarnTableAdapter implements ICommandExecutor {
} }
default: { default: {
String tagName = (opTag != null) ? opTag.name() : "null"; String tagName = (opTag != null) ? opTag.name() : "null";
Property[] props = new Property[] { new Property("STDERR", Property[] props = new Property[] { new Property(
PropConverter.asciiToHex("ERROR:Invalid command tag = [" CommandExecutor.STDERR, "ERROR:Invalid command tag = ["
+ tagName + "]")), }; + tagName + "]"), };
sHeader.setProperties(props); sHeader.setProperties(props);
break; break;
} }
@ -164,12 +159,10 @@ public class WarnTableAdapter implements ICommandExecutor {
* @return * @return
*/ */
private void addWatchWarn(Header header, String productId, String script) { private void addWatchWarn(Header header, String productId, String script) {
Property newProperty = new Property("STDERR", Property newProperty = new Property(CommandExecutor.STDERR,
PropConverter.asciiToHex("NORMAL:Adding productId " + productId "NORMAL:Adding productId " + productId + " to trigger.");
+ " to trigger.")); Property errProperty = new Property(CommandExecutor.STDERR,
Property errProperty = new Property("STDERR", "ERROR:Failure adding to state_ccc table.");
PropConverter
.asciiToHex("ERROR:Failure adding to state_ccc table."));
Property[] props = new Property[] { newProperty, }; Property[] props = new Property[] { newProperty, };
if (!textDB.addWatchWarn(productId, script)) { if (!textDB.addWatchWarn(productId, script)) {
@ -184,7 +177,7 @@ public class WarnTableAdapter implements ICommandExecutor {
* @param productId * @param productId
*/ */
private void getWatchWarn(Header header, String productId) { private void getWatchWarn(Header header, String productId) {
String PROP_FMT = "STDOUT"; String PROP_FMT = CommandExecutor.STDOUT;
Property[] props = null; Property[] props = null;
@ -193,20 +186,15 @@ public class WarnTableAdapter implements ICommandExecutor {
if (dataList.size() > 0) { if (dataList.size() > 0) {
props = new Property[dataList.size() + 2]; props = new Property[dataList.size() + 2];
int i = 0; int i = 0;
props[i] = new Property(PROP_FMT, props[i] = new Property(PROP_FMT, "PRODUCTID SCRIPT");
PropConverter.asciiToHex("PRODUCTID SCRIPT")); props[i] = new Property(PROP_FMT, "--------- ------");
props[i] = new Property(PROP_FMT,
PropConverter.asciiToHex("--------- ------"));
for (WatchWarn w : dataList) { for (WatchWarn w : dataList) {
props[i++] = new Property(PROP_FMT, props[i++] = new Property(PROP_FMT, String.format("%9s %s",
PropConverter.asciiToHex(String.format("%9s %s", w.getProductid(), w.getScript()));
w
.getProductid(), w.getScript())));
} }
} else { } else {
props = new Property[] { new Property("STDERR", props = new Property[] { new Property(CommandExecutor.STDERR,
PropConverter "ERROR:Failure reading from watch warn table."), };
.asciiToHex("ERROR:Failure reading from watch warn table.")), };
} }
header.setProperties(props); header.setProperties(props);
} }
@ -219,12 +207,10 @@ public class WarnTableAdapter implements ICommandExecutor {
* @return * @return
*/ */
private void deleteWatchWarn(Header header, String productId, String script) { private void deleteWatchWarn(Header header, String productId, String script) {
Property newProperty = new Property("STDERR", Property newProperty = new Property(CommandExecutor.STDERR,
PropConverter.asciiToHex("NORMAL:Deleting product id " "NORMAL:Deleting product id " + productId + " trigger.");
+ productId + " trigger.")); Property errProperty = new Property(CommandExecutor.STDERR,
Property errProperty = new Property("STDERR", "ERROR:Failure adding to state_ccc table.");
PropConverter
.asciiToHex("ERROR:Failure adding to state_ccc table."));
Property[] props = new Property[] { newProperty, }; Property[] props = new Property[] { newProperty, };
if (!textDB.deleteWatchWarn(productId, script)) { if (!textDB.deleteWatchWarn(productId, script)) {

View file

@ -62,6 +62,7 @@ import com.raytheon.uf.edex.plugin.text.subscription.util.SubscribeAction;
* 18Nov2008 1709 MW Fegan Initial creation * 18Nov2008 1709 MW Fegan Initial creation
* May 22, 2014 2536 bclement moved from autobldsrv to edex.plugin.text * May 22, 2014 2536 bclement moved from autobldsrv to edex.plugin.text
* removed duplicate SubscribeAction enum * removed duplicate SubscribeAction enum
* Aug 22, 2014 2926 bclement improved error handling for unknown operation
* *
* </pre> * </pre>
* *
@ -128,6 +129,11 @@ public class SubscribeRunner {
throw new EdexException("Unable to initialize ISubscribeRunner instance; null or empty operation specified - unable to continue"); throw new EdexException("Unable to initialize ISubscribeRunner instance; null or empty operation specified - unable to continue");
} }
SubscribeAction action = SubscribeAction.translate(oper); SubscribeAction action = SubscribeAction.translate(oper);
if (action == null) {
throw new EdexException(
"Unable to initialize ISubscriberunner instance; unable to find action for operation ["
+ oper + "]");
}
String className = action.getRunner(); String className = action.getRunner();
if (className == null) { if (className == null) {
throw new EdexException("Unable to initialize ISubscribeRunner instance; invalid operation [" + oper + "] specified - unable to continue"); throw new EdexException("Unable to initialize ISubscribeRunner instance; invalid operation [" + oper + "] specified - unable to continue");

View file

@ -23,12 +23,37 @@ import types
import lib.CommandLine as CL import lib.CommandLine as CL
import lib.InputOutput as IO import lib.InputOutput as IO
import lib.CommHandler as CH
import lib.Message as MSG
import lib.Util as util import lib.Util as util
import subscription.SubscriptionManager as SM import subscription.SubscriptionManager as SM
import conf.TDBConfig as config import conf.TDBConfig as config
import collections
from ufpy import ThriftClient
from dynamicserialize.dstypes.com.raytheon.uf.common.message import Message, Header, Property
from dynamicserialize.dstypes.com.raytheon.uf.edex.plugin.text.dbsrv import TextDBRequest
##############################################################################
# General exception to be raised when errors occur when processing messages
##############################################################################
class MessageError(Exception):
def __init__(self,value,cause=None):
self.value = value
self.cause = cause
def __str__(self):
msg = 'MessageError: ' + repr(self.value)
if self.cause is not None:
msg += "\n caused by " + repr(self.cause)
return msg
def __repr__(self):
return self.__str__()
# appends value to list assoticated with key in multimap if the key isn't
# present in the map. map must be defaultdict so that list is auto created
def appendIfNotPresent(multimap, key, value):
if key not in multimap:
multimap[key].append(value)
############################################################################## ##############################################################################
# Class implementing the text database (textdb) Command Line Interface (CLI) # Class implementing the text database (textdb) Command Line Interface (CLI)
@ -60,6 +85,7 @@ import conf.TDBConfig as config
# 04/07/11 8686 cjeanbap Fixed $ACTION has -i associated # 04/07/11 8686 cjeanbap Fixed $ACTION has -i associated
# 05/12/14 16954 kshrestha Added Multiple flag functionality for textdb # 05/12/14 16954 kshrestha Added Multiple flag functionality for textdb
# 08/15/14 2926 bclement Fixed hasSubOperations() # 08/15/14 2926 bclement Fixed hasSubOperations()
# 08/22/14 2926 bclement Switched to ThriftClient
############################################################################## ##############################################################################
class TextDB: class TextDB:
@ -209,24 +235,14 @@ class TextDB:
raise IO.InputOutputError("Unable to read product from standard input",e) raise IO.InputOutputError("Unable to read product from standard input",e)
# Generates the request message to be sent to the EDEX server. # Generates the request message to be sent to the EDEX server.
# The message is similar to
# <message>
# <header>
# <properties name="VIEW" value="text" />
# <properties name="OP" value="PUT" />
# <properties name="PRODID" value="CCCNNNXX" />
# <properties name="product" value="This is a test." />
# </header>
# </message>
# #
# return: # return:
# the generated message in XML format # the generated message in a serializable object
# raises: # raises:
# MessageError if any error occurs # MessageError if any error occurs
def __generateRequestMessage(self): def __generateRequestMessage(self):
try: try:
msg = MSG.Message(True) multimap = collections.defaultdict(list)
msg.initializeMessage(False)
commands = self.commands['command'] commands = self.commands['command']
isJoin = False isJoin = False
for command in commands: for command in commands:
@ -241,27 +257,28 @@ class TextDB:
if isinstance(value,types.IntType): if isinstance(value,types.IntType):
if args == config.MSG_VAR_ARGS: if args == config.MSG_VAR_ARGS:
for item in data: for item in data:
msg.addProperty(name=key,value=item,replace=False) multimap[key].append(item)
else: else:
if (len(commands) == 1) or (len(commands) == 3): l = len(commands)
if (l == 1) or (l == 3):
if ((key == "SITE") and (self.commands.get("site_node") is not None) and (len(self.commands.get("site_node")) == 0)): if ((key == "SITE") and (self.commands.get("site_node") is not None) and (len(self.commands.get("site_node")) == 0)):
val = str(os.getenv("sitename")) val = str(os.getenv("sitename"))
msg.addProperty(name=key,value=val,replace=True) appendIfNotPresent(multimap, key, val)
elif(isJoin == True): elif(isJoin == True):
msg.addProperty(name=key,value=data,replace=True) appendIfNotPresent(multimap, key, data)
isJoin = False isJoin = False
else: else:
msg.addProperty(name=key,value=data[value],replace=True) appendIfNotPresent(multimap, key, data[value])
else: else:
msg.addProperty(name=key,value=data,replace=True) appendIfNotPresent(multimap, key, data)
else: else:
msg.addProperty(name=key,value=value,replace=True) appendIfNotPresent(multimap, key, value)
operationalMode = os.getenv("OPERATIONAL_MODE", 'TRUE') operationalMode = os.getenv("OPERATIONAL_MODE", 'TRUE')
msg.addProperty(name='operational',value=operationalMode,replace=False) multimap['operational'].append(operationalMode)
return msg.getXML() return Message(header=Header(multimap=multimap))
except Exception,e: except Exception,e:
raise MSG.MessageError('unable to create message for textdb request',e) raise MessageError('unable to create message for textdb request',e)
# reads the command line and sets up the command data structure # reads the command line and sets up the command data structure
# #
# raises: # raises:
@ -324,14 +341,12 @@ class TextDB:
# return: # return:
# 0 if the message contained valid results, 0 otherwise # 0 if the message contained valid results, 0 otherwise
def __processRequestResponse(self,msg): def __processRequestResponse(self,msg):
psr = MSG.Message(True)
psr.parse(msg)
status = 0 status = 0
io = IO.InputOutput() io = IO.InputOutput()
# process the return message # process the return message
for prop in psr.getProperties(): for prop in msg.getHeader().getProperties():
name = prop['name'] name = prop.getName()
value = prop['value'] value = prop.getValue()
if name == 'STDERR': if name == 'STDERR':
parts = value.split(':',2) parts = value.split(':',2)
if parts[0] == 'ERROR': if parts[0] == 'ERROR':
@ -342,10 +357,8 @@ class TextDB:
io.setStream(sys.stdout) io.setStream(sys.stdout)
io.writeln(data=value) io.writeln(data=value)
return status return status
# Submits the request to the server and waits for a response. # Submits the request to the server and waits for a response.
# Does a quick check to eliminate an invalid response from the
# server.
# #
# args: # args:
# msg: the message to submit to the server # msg: the message to submit to the server
@ -353,22 +366,16 @@ class TextDB:
# the message received from the from the server, # the message received from the from the server,
# or Null if a connection error occurred. # or Null if a connection error occurred.
# raise: # raise:
# CommError if any error occurred. # ThriftRequestException if any error occurred.
def __submitRequestMessage(self,msg): def __submitRequestMessage(self,msg):
try: # send the request to the server
runner = self.commands.get('runner') host = os.getenv("DEFAULT_HOST", "localhost")
service = config.endpoint.get(runner) port = os.getenv("DEFAULT_PORT", "9581")
tClient = ThriftClient.ThriftClient(host, port)
# send the request to the server req = TextDBRequest()
connection=str(os.getenv("DEFAULT_HOST", "localhost") + ":" + os.getenv("DEFAULT_PORT", "9581")) req.setMessage(msg)
ch = CH.CommHandler(connection,service) return tClient.sendRequest(req)
ch.process(msg)
if not ch.isGoodStatus():
util.reportHTTPResponse(ch.formatResponse())
return None
return ch.getContents()
except Exception,e:
raise CH.CommError("Unable to submit request to server",e)
# Handles the LDAD (script) requests by # Handles the LDAD (script) requests by
# 1. morphing the command line to match the micro-engine command line # 1. morphing the command line to match the micro-engine command line
# 2. passing the modified command line to the micro-engine client # 2. passing the modified command line to the micro-engine client
@ -376,7 +383,7 @@ class TextDB:
# return: # return:
# returns the result of executing the micro-engine client # returns the result of executing the micro-engine client
# raise: # raise:
# propagates any exception received # propagates any exception received
def __handleScriptRequest(self): def __handleScriptRequest(self):
cmd = self.commands.get('command')[0] cmd = self.commands.get('command')[0]
fmt = config.convldad.get(cmd) fmt = config.convldad.get(cmd)
@ -395,7 +402,7 @@ class TextDB:
if (config.ldaddel == cmd): if (config.ldaddel == cmd):
temp = cline[len(cline)-1] temp = cline[len(cline)-1]
cline[len(cline)-1] = " ".join(temp.split('|')) cline[len(cline)-1] = " ".join(temp.split('|'))
sm = SM.SubscriptionManager(name='textdb',args=cline) sm = SM.SubscriptionManager(name='textdb',args=cline)
return sm.execute() return sm.execute()
@ -412,7 +419,7 @@ class TextDB:
self.__deleteWatchWarn() self.__deleteWatchWarn()
self.__deleteSubscriptions() self.__deleteSubscriptions()
except Exception,e: except Exception,e:
raise MSG.MessageError('unable to create message for textdb request',e) raise MessageError('unable to create message for textdb request',e)
try: try:
for i in range(len(args)): for i in range(len(args)):
f = open(args[i],'r') f = open(args[i],'r')
@ -420,55 +427,54 @@ class TextDB:
# remove all white-spaces at beginning of the line. # remove all white-spaces at beginning of the line.
line = line.lstrip() line = line.lstrip()
if (line.find('#') == -1): if (line.find('#') == -1):
try: try:
values = line.split(' ', 1) values = line.split(' ', 1)
try: try:
msg = MSG.Message(True) props = []
msg.initializeMessage(False) props.append(Property(name='VIEW',value='warn'))
msg.addProperty(name='VIEW',value='warn',replace=False) props.append(Property(name='OP',value='PUT'))
msg.addProperty(name='OP',value='PUT',replace=False) props.append(Property(name='PRODID',value=values[0]))
msg.addProperty(name='PRODID',value=values[0],replace=False) props.append(Property(name='SCRIPT',value=values[1]))
msg.addProperty(name='SCRIPT',value=values[1],replace=False) msg = Message(header=Header(props))
except Exception,e: except Exception,e:
raise MSG.MessageError('unable to create message for textdb request',e) raise MessageError('unable to create message for textdb request',e)
if ((len(values[0]) >= 8) & (len(values[1].strip('\r\n')) > 0)): if ((len(values[0]) >= 8) & (len(values[1].strip('\r\n')) > 0)):
# print "Insert Subscription [" + values[0] + "] Status:" + str(sm.execute()) # print "Insert Subscription [" + values[0] + "] Status:" + str(sm.execute())
cline = ['-o','add', '-t','ldad', '-r','ldad', '-p', values[0], '-f', values[1], '-c','%TRIGGER%'] cline = ['-o','add', '-t','ldad', '-r','ldad', '-p', values[0], '-f', values[1], '-c','%TRIGGER%']
sm = SM.SubscriptionManager(name='textdb',args=cline) sm = SM.SubscriptionManager(name='textdb',args=cline)
sm.execute() sm.execute()
msg = self.__submitRequestMessage(msg.getXML()) msg = self.__submitRequestMessage(msg)
status = self.__processRequestResponse(msg) status = self.__processRequestResponse(msg)
except ValueError: except ValueError:
util.printMessage(sys.stderr, util.printMessage(sys.stderr,
header='Error processing line', header='Error processing line',
body=line) body=line)
finally: finally:
f.close() f.close()
else: else:
raise MSG.MessageError('Unable to locate file: ' + args[0]) raise MessageError('Unable to locate file: ' + args[0])
else: else:
self.__deleteSubscriptions() self.__deleteSubscriptions()
return return
# #
# #
# #
def __deleteWatchWarn(self): def __deleteWatchWarn(self):
msg = MSG.Message(True) props = []
msg.initializeMessage(False) props.append(Property(name='VIEW',value='warn'))
msg.addProperty(name='VIEW',value='warn',replace=False) props.append(Property(name='OP',value='DELETE'))
msg.addProperty(name='OP',value='DELETE',replace=False) msg = self.__submitRequestMessage(Message(header=Header(props)))
msg = self.__submitRequestMessage(msg.getXML())
status = self.__processRequestResponse(msg) status = self.__processRequestResponse(msg)
# #
# #
# #
def __deleteSubscriptions(self): def __deleteSubscriptions(self):
cline = ['-o','delete'] cline = ['-o','delete']
sm = SM.SubscriptionManager(name='textdb',args=cline) sm = SM.SubscriptionManager(name='textdb',args=cline)
sm.execute() sm.execute()
# Determine if command line has sub operations # Determine if command line has sub operations
# Returns true if any flags in self.commands[CL.DEFAULT_KEY] # Returns true if any flags in self.commands[CL.DEFAULT_KEY]

View file

@ -0,0 +1,33 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated against equivalent DynamicSerialize Java class
class Body(object):
def __init__(self):
self.responses = None
def getResponses(self):
return self.responses
def setResponses(self, responses):
self.responses = responses

View file

@ -0,0 +1,43 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated against equivalent DynamicSerialize Java class
from Property import Property
class Header(object):
def __init__(self, properties=None, multimap=None):
if properties is None:
self.properties = []
else:
self.properties = properties
if multimap is not None:
for k, l in multimap.iteritems():
for v in l:
self.properties.append(Property(k, v))
def getProperties(self):
return self.properties
def setProperties(self, properties):
self.properties = properties

View file

@ -0,0 +1,40 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated against equivalent DynamicSerialize Java class
class Message(object):
def __init__(self, header=None, body=None):
self.header = header
self.body = body
def getHeader(self):
return self.header
def setHeader(self, header):
self.header = header
def getBody(self):
return self.body
def setBody(self, body):
self.body = body

View file

@ -0,0 +1,40 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated against equivalent DynamicSerialize Java class
class Property(object):
def __init__(self, name=None, value=None):
self.name = name
self.value = value
def getName(self):
return self.name
def setName(self, name):
self.name = name
def getValue(self):
return self.value
def setValue(self, value):
self.value = value

View file

@ -18,6 +18,13 @@
# further licensing information. # further licensing information.
## ##
__all__ = [
'Body',
'Header',
'Message',
'Property',
'WsId'
]
# #
# Package definition for com.raytheon.uf.common.message # Package definition for com.raytheon.uf.common.message
@ -28,13 +35,13 @@
# Date Ticket# Engineer Description # Date Ticket# Engineer Description
# ------------ ---------- ----------- -------------------------- # ------------ ---------- ----------- --------------------------
# 09/16/10 dgilling Initial Creation. # 09/16/10 dgilling Initial Creation.
# # 08/19/14 2926 bclement added Message files
# #
# #
__all__ = [ from Body import Body
'WsId' from Header import Header
] from Message import Message
from Property import Property
from WsId import WsId from WsId import WsId

View file

@ -0,0 +1,27 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated by PythonFileGenerator
__all__ = [
'plugin'
]

View file

@ -0,0 +1,27 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated by PythonFileGenerator
__all__ = [
'text'
]

View file

@ -0,0 +1,27 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated by PythonFileGenerator
__all__ = [
'dbsrv'
]

View file

@ -0,0 +1,33 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated against equivalent DynamicSerialize Java class
class TextDBRequest(object):
def __init__(self):
self.message = None
def getMessage(self):
return self.message
def setMessage(self, message):
self.message = message

View file

@ -0,0 +1,28 @@
##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
# File auto-generated by PythonFileGenerator
__all__ = [
'TextDBRequest'
]
from TextDBRequest import TextDBRequest