Search in sources :

Example 21 with WorkflowException

use of org.onosproject.workflow.api.WorkflowException in project onos by opennetworkinglab.

the class WorkflowRestApi method invoke.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/invoke")
public Response invoke(InputStream stream) {
    ObjectNode ret = JsonNodeFactory.instance.objectNode();
    try {
        ObjectNode payload = readTreeFromStream(mapper(), stream);
        String operation = payload.path(OPERATION).asText();
        if (!(WORKFLOW_INVOKE.equals(operation))) {
            log.error("Operation is not matched");
            return Response.status(BAD_REQUEST).entity("Operation is not matched!").build();
        }
        JsonNode wfDescJson = payload.path(PARAMS).deepCopy();
        service.invokeWorkflow(wfDescJson);
        ret.put(WF_ID, wfDescJson.path(WF_ID).asText());
        return ok(ret).build();
    } catch (JsonProcessingException e) {
        log.error("Failed to get json ", e);
        ret.put(WF_ID, "Failed to get Json " + e.getCause());
        return Response.status(BAD_REQUEST).entity(ret).build();
    } catch (IOException e) {
        log.error("Failed to get request body ", e);
        ret.put(WF_ID, "Failed to get request body " + e.getCause());
        return Response.status(INTERNAL_SERVER_ERROR).entity(ret).build();
    } catch (WorkflowException e) {
        log.error("Failed to invoke workflow ", e);
        ret.put(WF_ID, "Failed to invoke workflow " + e.getCause());
        return Response.status(INTERNAL_SERVER_ERROR).entity(ret).build();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WorkflowException(org.onosproject.workflow.api.WorkflowException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 22 with WorkflowException

use of org.onosproject.workflow.api.WorkflowException in project onos by opennetworkinglab.

the class RestAccessInfo method valueOf.

/**
 * Builds RestAccessInfo from json.
 * @param root json root node for RestAccessinfo
 * @return REST access information
 * @throws WorkflowException workflow exception
 */
public static RestAccessInfo valueOf(JsonNode root) throws WorkflowException {
    JsonNode node = root.at(ptr(REMOTE_IP));
    if (node == null || !(node instanceof TextNode)) {
        throw new WorkflowException("invalid remoteIp for " + root);
    }
    IpAddress remoteIp = IpAddress.valueOf(node.asText());
    node = root.at(ptr(PORT));
    if (node == null || !(node instanceof NumericNode)) {
        throw new WorkflowException("invalid port for " + root);
    }
    TpPort tpPort = TpPort.tpPort(node.asInt());
    node = root.at(ptr(USER));
    if (node == null || !(node instanceof TextNode)) {
        throw new WorkflowException("invalid user for " + root);
    }
    String strUser = node.asText();
    node = root.at(ptr(PASSWORD));
    if (node == null || !(node instanceof TextNode)) {
        throw new WorkflowException("invalid password for " + root);
    }
    String strPassword = node.asText();
    return new RestAccessInfo(remoteIp, tpPort, strUser, strPassword);
}
Also used : WorkflowException(org.onosproject.workflow.api.WorkflowException) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) NumericNode(com.fasterxml.jackson.databind.node.NumericNode)

Example 23 with WorkflowException

use of org.onosproject.workflow.api.WorkflowException in project onos by opennetworkinglab.

the class WorkflowNetConfig method getRpcDescriptions.

public Collection<RpcDescription> getRpcDescriptions() throws WorkflowException {
    JsonNode node = object.at(RPC_PTR);
    if (!(node instanceof ArrayNode)) {
        throw new WorkflowException("invalid rpc for " + object);
    }
    ArrayNode rpcArrayNode = (ArrayNode) node;
    List<RpcDescription> rpcDescriptions = new ArrayList<>();
    for (JsonNode rpcNode : rpcArrayNode) {
        rpcDescriptions.add(DefaultRpcDescription.valueOf(rpcNode));
    }
    return rpcDescriptions;
}
Also used : WorkflowException(org.onosproject.workflow.api.WorkflowException) RpcDescription(org.onosproject.workflow.api.RpcDescription) DefaultRpcDescription(org.onosproject.workflow.api.DefaultRpcDescription) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 24 with WorkflowException

use of org.onosproject.workflow.api.WorkflowException in project onos by opennetworkinglab.

the class SshAccessInfo method valueOf.

/**
 * Builds SshAccessInfo from json.
 * @param root json root node for SshAccessinfo
 * @return SSH access information
 * @throws WorkflowException workflow exception
 */
public static SshAccessInfo valueOf(JsonNode root) throws WorkflowException {
    JsonNode node = root.at(ptr(REMOTE_IP));
    if (node == null || !(node instanceof TextNode)) {
        throw new WorkflowException("invalid remoteIp for " + root);
    }
    IpAddress sshIp = IpAddress.valueOf(node.asText());
    node = root.at(ptr(PORT));
    if (node == null || !(node instanceof NumericNode)) {
        throw new WorkflowException("invalid port for " + root);
    }
    TpPort sshPort = TpPort.tpPort(node.asInt());
    node = root.at(ptr(USER));
    if (node == null || !(node instanceof TextNode)) {
        throw new WorkflowException("invalid user for " + root);
    }
    String sshUser = node.asText();
    node = root.at(ptr(PASSWORD));
    if (node == null || !(node instanceof TextNode)) {
        throw new WorkflowException("invalid password for " + root);
    }
    String sshPassword = node.asText();
    node = root.at(ptr(KEYFILE));
    if (node == null || !(node instanceof TextNode)) {
        throw new WorkflowException("invalid keyfile for " + root);
    }
    String sshKeyfile = node.asText();
    return new SshAccessInfo(sshIp, sshPort, sshUser, sshPassword, sshKeyfile);
}
Also used : WorkflowException(org.onosproject.workflow.api.WorkflowException) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) NumericNode(com.fasterxml.jackson.databind.node.NumericNode)

Aggregations

WorkflowException (org.onosproject.workflow.api.WorkflowException)24 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 Workflow (org.onosproject.workflow.api.Workflow)9 WorkflowContext (org.onosproject.workflow.api.WorkflowContext)7 Worklet (org.onosproject.workflow.api.Worklet)7 ProgramCounter (org.onosproject.workflow.api.ProgramCounter)5 SystemWorkflowContext (org.onosproject.workflow.api.SystemWorkflowContext)5 WorkflowService (org.onosproject.workflow.api.WorkflowService)5 StorageException (org.onosproject.store.service.StorageException)4 NumericNode (com.fasterxml.jackson.databind.node.NumericNode)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)3 ArrayList (java.util.ArrayList)3 IpAddress (org.onlab.packet.IpAddress)3 TpPort (org.onlab.packet.TpPort)3 WorkletDescription (org.onosproject.workflow.api.WorkletDescription)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Annotation (java.lang.annotation.Annotation)2 Field (java.lang.reflect.Field)2