use of org.apache.streampipes.connect.api.exception.AdapterException in project incubator-streampipes by apache.
the class Plc4xS7Adapter method before.
/**
* This method is executed when the adapter is started. A connection to the PLC is initialized
* @throws AdapterException
*/
@Override
protected void before() throws AdapterException {
// Extract user input
getConfigurations(adapterDescription);
this.driverManager = new PooledPlcDriverManager();
try (PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip)) {
if (!plcConnection.getMetadata().canRead()) {
this.LOG.error("The S7 on IP: " + this.ip + " does not support reading data");
}
} catch (PlcConnectionException e) {
this.LOG.error("Could not establish connection to S7 with ip " + this.ip, e);
} catch (Exception e) {
this.LOG.error("Could not close connection to S7 with ip " + this.ip, e);
}
}
use of org.apache.streampipes.connect.api.exception.AdapterException in project incubator-streampipes by apache.
the class RosBridgeAdapter method getSchema.
@Override
public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
getConfigurations(adapterDescription);
Ros ros = new Ros(host, port);
boolean connect = ros.connect();
if (!connect) {
throw new AdapterException("Could not connect to ROS bridge Endpoint: " + host + " with port: " + port);
}
String topicType = getMethodType(ros, topic);
GetNEvents getNEvents = new GetNEvents(topic, topicType, ros);
Thread t = new Thread(getNEvents);
t.start();
while (getNEvents.getEvents().size() < 1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
t.interrupt();
ros.disconnect();
EventSchema eventSchema = this.jsonObjectParser.getEventSchema(getNEvents.getEvents());
GuessSchema guessSchema = new GuessSchema();
guessSchema.setEventSchema(eventSchema);
return guessSchema;
}
use of org.apache.streampipes.connect.api.exception.AdapterException in project incubator-streampipes by apache.
the class OpcUaUtil method getSchema.
/**
* OPC UA specific implementation of {@link org.apache.streampipes.connect.adapter.Adapter}
* @param adapterStreamDescription
* @return guess schema
* @throws AdapterException
* @throws ParseException
*/
public static GuessSchema getSchema(SpecificAdapterStreamDescription adapterStreamDescription) throws AdapterException, ParseException {
GuessSchema guessSchema = new GuessSchema();
EventSchema eventSchema = new EventSchema();
List<EventProperty> allProperties = new ArrayList<>();
SpOpcUaClient spOpcUaClient = new SpOpcUaClient(SpOpcUaConfigBuilder.from(adapterStreamDescription));
try {
spOpcUaClient.connect();
OpcUaNodeBrowser nodeBrowser = new OpcUaNodeBrowser(spOpcUaClient.getClient(), spOpcUaClient.getSpOpcConfig());
List<OpcNode> selectedNodes = nodeBrowser.findNodes();
if (!selectedNodes.isEmpty()) {
for (OpcNode opcNode : selectedNodes) {
if (opcNode.hasUnitId()) {
allProperties.add(PrimitivePropertyBuilder.create(opcNode.getType(), opcNode.getLabel()).label(opcNode.getLabel()).measurementUnit(new URI(opcNode.getQudtURI())).build());
} else {
allProperties.add(PrimitivePropertyBuilder.create(opcNode.getType(), opcNode.getLabel()).label(opcNode.getLabel()).build());
}
}
}
spOpcUaClient.disconnect();
} catch (Exception e) {
throw new AdapterException("Could not guess schema for opc node! " + e.getMessage());
}
eventSchema.setEventProperties(allProperties);
guessSchema.setEventSchema(eventSchema);
return guessSchema;
}
use of org.apache.streampipes.connect.api.exception.AdapterException in project incubator-streampipes by apache.
the class OpcUaUtil method retrieveDataTypesFromServer.
/**
* connects to each node individually and updates the data type in accordance to the data from the server.
* @param opcNodes List of opcNodes where the data type is not determined appropriately
*/
public static void retrieveDataTypesFromServer(OpcUaClient client, List<OpcNode> opcNodes) throws AdapterException {
for (OpcNode opcNode : opcNodes) {
try {
UInteger dataTypeId = (UInteger) client.getAddressSpace().getVariableNode(opcNode.getNodeId()).getDataType().getIdentifier();
OpcUaTypes.getType(dataTypeId);
opcNode.setType(OpcUaTypes.getType(dataTypeId));
} catch (UaException e) {
throw new AdapterException("Could not guess schema for opc node! " + e.getMessage());
}
}
}
use of org.apache.streampipes.connect.api.exception.AdapterException in project incubator-streampipes by apache.
the class MySqlClient method connect.
public void connect() throws AdapterException {
checkJdbcDriver();
String server = "jdbc:mysql://" + host + ":" + port + "/" + "?sslMode=DISABLED&allowPublicKeyRetrieval=true";
try {
connection = DriverManager.getConnection(server, username, password);
} catch (SQLException e) {
throw new AdapterException("Could not connect to server: " + e.getMessage());
}
}
Aggregations