Search in sources :

Example 1 with AdapterException

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);
    }
}
Also used : PlcConnectionException(org.apache.plc4x.java.api.exceptions.PlcConnectionException) PlcConnection(org.apache.plc4x.java.api.PlcConnection) PlcConnectionException(org.apache.plc4x.java.api.exceptions.PlcConnectionException) AdapterException(org.apache.streampipes.connect.api.exception.AdapterException) ExecutionException(java.util.concurrent.ExecutionException) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager)

Example 2 with AdapterException

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;
}
Also used : EventSchema(org.apache.streampipes.model.schema.EventSchema) Ros(edu.wpi.rail.jrosbridge.Ros) AdapterException(org.apache.streampipes.connect.api.exception.AdapterException) GuessSchema(org.apache.streampipes.model.connect.guess.GuessSchema)

Example 3 with AdapterException

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;
}
Also used : OpcUaNodeBrowser(org.apache.streampipes.connect.iiot.adapters.opcua.OpcUaNodeBrowser) EventSchema(org.apache.streampipes.model.schema.EventSchema) OpcNode(org.apache.streampipes.connect.iiot.adapters.opcua.OpcNode) ArrayList(java.util.ArrayList) EventProperty(org.apache.streampipes.model.schema.EventProperty) AdapterException(org.apache.streampipes.connect.api.exception.AdapterException) SpOpcUaClient(org.apache.streampipes.connect.iiot.adapters.opcua.SpOpcUaClient) URI(java.net.URI) AdapterException(org.apache.streampipes.connect.api.exception.AdapterException) UaException(org.eclipse.milo.opcua.stack.core.UaException) ParseException(org.apache.streampipes.connect.api.exception.ParseException) GuessSchema(org.apache.streampipes.model.connect.guess.GuessSchema)

Example 4 with AdapterException

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());
        }
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) OpcNode(org.apache.streampipes.connect.iiot.adapters.opcua.OpcNode) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) AdapterException(org.apache.streampipes.connect.api.exception.AdapterException)

Example 5 with AdapterException

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());
    }
}
Also used : AdapterException(org.apache.streampipes.connect.api.exception.AdapterException)

Aggregations

AdapterException (org.apache.streampipes.connect.api.exception.AdapterException)37 IOException (java.io.IOException)10 AdapterDescription (org.apache.streampipes.model.connect.adapter.AdapterDescription)8 NoServiceEndpointsAvailableException (org.apache.streampipes.commons.exceptions.NoServiceEndpointsAvailableException)6 ParseException (org.apache.streampipes.connect.api.exception.ParseException)5 GuessSchema (org.apache.streampipes.model.connect.guess.GuessSchema)5 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 EventSchema (org.apache.streampipes.model.schema.EventSchema)3 ExecutionException (java.util.concurrent.ExecutionException)2 OpcNode (org.apache.streampipes.connect.iiot.adapters.opcua.OpcNode)2 EventProperty (org.apache.streampipes.model.schema.EventProperty)2 StaticPropertyExtractor (org.apache.streampipes.sdk.extractor.StaticPropertyExtractor)2 Datatypes (org.apache.streampipes.sdk.utils.Datatypes)2 UaException (org.eclipse.milo.opcua.stack.core.UaException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Unit (com.github.jqudt.Unit)1 BinaryLogClient (com.github.shyiko.mysql.binlog.BinaryLogClient)1