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();
}
}
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);
}
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;
}
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);
}
Aggregations