Search in sources :

Example 36 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class BPELScript method removeUnnecessaryNodes.

// private GpelSequence createMainSequence() throws GraphException {
// GpelSequence sequence = new GpelSequence(this.bpelNS);
// 
// // Remove InputNodes and MemoNodes.
// removeUnnecessaryNodes(this.remainNodes);
// 
// addInitialReceive(sequence);
// 
// addBlock(this.remainNodes, sequence);
// 
// addFinalReply(sequence);
// 
// if (this.remainNodes.size() > 0) {
// throw new GraphException("Some node(s) are not connected.");
// }
// 
// return sequence;
// }
// 
// private void addInitialReceive(GpelSequence sequence) {
// // Create a partner link
// String partnerLinkName = WORKFLOW_PARTNER_LINK;
// XmlNamespace partnerLinkTypeNS = this.workflowWSDL.getTargetNamespace();
// String partnerLinkTypeName = this.workflowPrefix + PARTNER_LINK_TYPE_SUFFIX;
// String myRollName = this.workflowPrefix + MY_ROLE_SUFFIX;
// 
// this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkTypeName, myRollName, null);
// this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, myRollName,
// this.workflowWSDL.getPortTypeQName());
// 
// // Create a variable
// this.process.addMessageVariable(WORKFLOW_INPUT_NAME, this.targetNamespace,
// this.workflowWSDL.getWorkflowInputMessageName());
// 
// GpelReceive receive = new GpelReceive(this.bpelNS, WORKFLOW_PARTNER_LINK, this.workflowWSDL.getPortTypeQName(),
// this.workflowWSDL.getWorkflowOperationName());
// receive.setGpelVariableName(WORKFLOW_INPUT_NAME);
// sequence.addActivity(receive);
// }
// 
// private void addFinalReply(GpelSequence sequence) throws GraphException {
// // Create a variable
// this.process.addMessageVariable(WORKFLOW_OUTPUT_NAME, this.targetNamespace,
// this.workflowWSDL.getWorkflowOutputMessageName());
// 
// List<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>();
// List<OutputNode> outputNodes = GraphUtil.getNodes(this.graph, OutputNode.class);
// this.remainNodes.removeAll(outputNodes);
// for (OutputNode outputNode : outputNodes) {
// Port port = outputNode.getPort();
// GpelAssignCopyFrom from = createAssignCopyFrom(port);
// GpelAssignCopyTo to = createAssignCopyTo(port, false);
// 
// copies.add(new GpelAssignCopy(this.bpelNS, from, to));
// }
// 
// if (copies.size() != 0) {
// // When there is no outputs, we don't create assign.
// GpelAssign assign = new GpelAssign(this.bpelNS, copies);
// sequence.addActivity(assign);
// }
// 
// GpelReply reply = new GpelReply(this.bpelNS, WORKFLOW_PARTNER_LINK, this.workflowWSDL.getPortTypeQName(),
// this.workflowWSDL.getWorkflowOperationName());
// reply.setVariableName(WORKFLOW_OUTPUT_NAME);
// sequence.addActivity(reply);
// }
// 
// /**
// * @param block
// * @param sequence
// * @throws GraphException
// */
// private void addBlock(Collection<Node> block, GpelSequence sequence) throws GraphException {
// List<Node> nextNodes = getNextExecutableNodes(block);
// while (nextNodes.size() > 0) {
// block.removeAll(nextNodes);
// removeUnnecessaryNodes(nextNodes);
// if (nextNodes.size() == 0) {
// // Everything was uncessary nodes (constants, etc.). Move on.
// } else if (nextNodes.size() == 1) {
// addSingle(nextNodes.get(0), block, sequence);
// } else if (nextNodes.size() > 1) {
// // XXX The algorithm used here is not efficient. It introduces
// // unnessary barriers.
// addFlow(nextNodes, block, sequence);
// } else {
// // Should not happen.
// throw new WorkflowRuntimeException("nextNodes.size(): " + nextNodes.size());
// }
// nextNodes = getNextExecutableNodes(block);
// }
// }
// 
// private void addFlow(List<Node> nextNodes, Collection<Node> block, GpelSequence sequence) throws GraphException {
// GpelFlow flow = new GpelFlow(this.bpelNS);
// for (Node node : nextNodes) {
// GpelSequence childSequence = new GpelSequence(this.bpelNS);
// flow.addActivity(childSequence);
// addSingle(node, block, childSequence);
// }
// sequence.addActivity(flow);
// }
// 
// // TODO: Add xml to BPEL
// private void addSingle(Node node, Collection<Node> block, GpelSequence sequence) throws GraphException {
// logger.debug("Processing + " + node.getID());
// if (node instanceof WSNode) {
// addInvoke((WSNode) node, sequence);
// } else if (node instanceof ConstantNode) {
// // nothing
// } else if (node instanceof ForEachNode) {
// addForEach((ForEachNode) node, block, sequence);
// } else if (node instanceof EndForEachNode) {
// // nothing.
// } else if (node instanceof IfNode) {
// addIf((IfNode) node, block, sequence);
// } else if (node instanceof EndifNode) {
// // nothing
// } else if (node instanceof ReceiveNode) {
// addReceive((ReceiveNode) node, sequence);
// } else if (node instanceof BlockNode) {
// addBlock((BlockNode) node, block, sequence);
// } else if (node instanceof EndBlockNode) {
// // nothing
// } else if (node instanceof StreamSourceNode) {
// addStreamSource((StreamSourceNode) node, sequence);
// } else if (node instanceof ExitNode) {
// addExit((ExitNode) node, sequence);
// } else if (node instanceof ResourceNode) {
// // nothing
// } else {
// 
// throw new GraphException(node.getClass().getName() + " is not supported.");
// }
// }
// 
// /**
// * @param node
// * @param sequence
// */
// private void addStreamSource(StreamSourceNode node, GpelSequence sequence) {
// GpelFlow flow = new GpelFlow(this.bpelNS);
// new GpelSequence(this.bpelNS);
// sequence.addActivity(flow);
// 
// }
// 
// /**
// * @param node
// * @param sequence
// */
// private void addExit(ExitNode node, GpelSequence sequence) {
// sequence.xml().addElement(this.bpelNS, "exit");
// }
// 
// private void addInvoke(WSNode node, GpelSequence sequence) throws GraphException {
// String id = node.getID();
// 
// WSComponent wsdlComponent = node.getComponent();
// String operation = wsdlComponent.getOperationName();
// 
// QName portTypeQName = wsdlComponent.getPortTypeQName();
// XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(id.toLowerCase(), portTypeQName.getNamespaceURI(),
// false, this.process.xml());
// 
// // Variable
// String inputVariableName = id + INPUT_SUFFIX;
// this.process.addMessageVariable(inputVariableName, namespace, portTypeQName.getLocalPart());
// String outputVariableName = id + OUTPUT_SUFFIX;
// this.process.addMessageVariable(outputVariableName, namespace, portTypeQName.getLocalPart());
// 
// // Assign
// List<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>();
// for (Port port : node.getInputPorts()) {
// Port fromPort = port.getFromPort();
// if (fromPort == null) {
// // optional input
// continue;
// }
// GpelAssignCopyFrom from = createAssignCopyFrom(port);
// GpelAssignCopyTo to = createAssignCopyTo(port, true);
// 
// GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to);
// copies.add(copy);
// }
// 
// GpelAssign assign = new GpelAssign(this.bpelNS, copies);
// sequence.addActivity(assign);
// 
// PartnerLinkRole partnerRoll = this.workflowWSDL.getPartnerRoll(portTypeQName);
// if (partnerRoll == null) {
// String partnerLinkTypeName = id + PARTNER_LINK_TYPE_SUFFIX;
// String partnerRollName = id + PARTNER_ROLE_SUFFIX;
// partnerRoll = this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, partnerRollName,
// portTypeQName);
// }
// PartnerLinkType partnerLinkType = partnerRoll.getPartnerLinkType();
// 
// // partnerLink
// String partnerLinkName = createPartnerLinkName(id);
// XmlNamespace partnerLinkTypeNS = this.targetNamespace;
// this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkType.getName(), null,
// partnerRoll.getName());
// 
// // Invoke
// GpelInvoke invoke = new GpelInvoke(this.bpelNS, partnerLinkName, namespace, portTypeQName.getLocalPart(),
// operation);
// invoke.setName(INVOKE_NAME_PREFIX + id);
// invoke.setInputVariableName(inputVariableName);
// invoke.setOutputVariableName(outputVariableName);
// 
// sequence.addActivity(invoke);
// }
// /**
// * Creates BpelAssignCopyFrom for a specified port.
// *
// * @param port
// * @return The BpelAssignCopyFrom created
// * @throws GraphException
// */
// private GpelAssignCopyFrom createAssignCopyFrom(Port port) throws GraphException {
// GpelAssignCopyFrom from = new GpelAssignCopyFrom(this.bpelNS);
// 
// Port fromPort = port.getFromPort();
// Node fromNode = fromPort.getNode();
// if (fromNode instanceof InputNode) {
// from.setVariable(WORKFLOW_INPUT_NAME);
// from.setPart(WorkflowWSDL.INPUT_PART_NAME);
// from.setQuery("/" + this.typesNamespace.getPrefix() + ":"
// + this.workflowWSDL.getWorkflowInputMessageElelmentName() + "/" + fromNode.getID());
// } else if (fromNode instanceof ConstantNode) {
// ConstantNode constNode = (ConstantNode) fromNode;
// Object value = constNode.getValue();
// // The namaspace and name of the literal element will be set
// // correctly in from.setLiteral().
// XmlElement literalElement = XMLUtil.BUILDER.newFragment(GpelAssignCopyFrom.LITERAL_EL);
// literalElement.addChild(value);
// from.setLiteral(literalElement);
// } else if (fromNode instanceof WSNode) {
// String fromID = fromNode.getID();
// WSComponent fromWsdlComponent = (WSComponent) fromNode.getComponent();
// 
// WSComponentPort fromWsdlPort = (WSComponentPort) fromPort.getComponentPort();
// 
// from.setVariable(fromID + OUTPUT_SUFFIX);
// from.setPart(fromWsdlComponent.getOutputPartName());
// 
// if (fromWsdlPort.isSchemaUsed()) {
// String typesTargetNamespace = fromWsdlPort.getTargetNamespace();
// XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(fromID.toLowerCase() + TYPENS_SUFFIX,
// typesTargetNamespace, false, this.process.xml());
// 
// from.setQuery("/" + namespace.getPrefix() + ":" + fromWsdlComponent.getOutputTypeName() + "/"
// + fromWsdlPort.getName());
// } else {
// // No query needed?
// }
// } else if (fromNode instanceof ForEachNode) {
// from.setVariable(fromNode.getID() + FOREACH_VALUE_SUFFIX);
// } else if (fromNode instanceof EndForEachNode) {
// from.setVariable(fromNode.getID() + ARRAY_SUFIX);
// } else if (fromNode instanceof EndifNode) {
// // endif has multiple outputs, so we use port ID here.
// from.setVariable(fromPort.getID() + OUTPUT_SUFFIX);
// } else if (fromNode instanceof ReceiveNode) {
// if (fromPort instanceof EPRPort) {
// from.setPartnerLink(fromNode.getID() + PARTNER_LINK_NAME_SUFFIX);
// from.setEndpointReference("myRole");
// } else {
// from.setVariable(fromNode.getID() + INPUT_SUFFIX);
// }
// } else if (fromNode instanceof InstanceNode) {
// // no op
// } else {
// throw new GraphException("Unexpected node," + fromNode.getClass().getName() + " is connected");
// }
// return from;
// }
// 
// /**
// * Creates BpelAssignCopyFrom for a specified port.
// *
// * @param toPort
// * @param input
// * @return The GpelAssignCopyTo created
// */
// private GpelAssignCopyTo createAssignCopyTo(Port toPort, boolean input) {
// GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS);
// 
// Node toNode = toPort.getNode();
// if (toNode instanceof OutputNode) {
// to.setVariable(WORKFLOW_OUTPUT_NAME);
// to.setPart(WorkflowWSDL.OUTPUT_PART_NAME);
// to.setQuery("/" + this.typesNamespace.getPrefix() + ":"
// + this.workflowWSDL.getWorkflowOutputMessageElementName() + "/" + toNode.getID());
// } else {
// WSComponentPort toComponentPort = (WSComponentPort) toPort.getComponentPort();
// 
// String toID = toNode.getID();
// WSComponent toWSComponent = (WSComponent) toNode.getComponent();
// to.setVariable(toID + INPUT_SUFFIX);
// to.setPart(toWSComponent.getInputPartName());
// 
// if (toComponentPort.isSchemaUsed()) {
// // Normal case.
// // e.g. <part name="name" type="typens:fooType">
// String typesTargetNamespace = toComponentPort.getTargetNamespace();
// XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(toID.toLowerCase() + TYPENS_SUFFIX,
// typesTargetNamespace, false, this.process.xml());
// 
// String typeName = input ? toWSComponent.getInputTypeName() : toWSComponent.getOutputTypeName();
// to.setQuery("/" + namespace.getPrefix() + ":" + typeName + "/" + toComponentPort.getName());
// } else {
// // e.g. <part name="name" type="xsd:string">
// // No query is needed?
// }
// }
// return to;
// }
private void removeUnnecessaryNodes(List<Node> block) {
    List<Node> unnecessaryNodes = new ArrayList<Node>();
    for (Node node : block) {
        if (node instanceof InputNode || node instanceof MemoNode || node instanceof ConstantNode) {
            unnecessaryNodes.add(node);
        }
    }
    block.removeAll(unnecessaryNodes);
}
Also used : InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) ConstantNode(org.apache.airavata.workflow.model.graph.system.ConstantNode) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) BlockNode(org.apache.airavata.workflow.model.graph.system.BlockNode) IfNode(org.apache.airavata.workflow.model.graph.system.IfNode) EndBlockNode(org.apache.airavata.workflow.model.graph.system.EndBlockNode) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode) Node(org.apache.airavata.workflow.model.graph.Node) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) ConstantNode(org.apache.airavata.workflow.model.graph.system.ConstantNode) EndifNode(org.apache.airavata.workflow.model.graph.system.EndifNode) OutputNode(org.apache.airavata.workflow.model.graph.system.OutputNode) ArrayList(java.util.ArrayList) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode)

Example 37 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class BPELScript method getBlockBlock.

// /**
// * @param node
// * @param block
// * @param sequence
// */
// private void addReceive(ReceiveNode node, GpelSequence sequence) {
// String id = node.getID();
// String operationName = id;
// 
// // Create this operation and type in WSDL.
// WsdlPortType portType = this.workflowWSDL.addReceivePortType(operationName, node);
// QName portTypeQName = portType.getQName();
// 
// // Partner link
// String partnerLinkName = createPartnerLinkName(id);
// XmlNamespace partnerLinkTypeNS = this.targetNamespace;
// String partnerLinkTypeName = id + PARTNER_LINK_TYPE_SUFFIX;
// String myRollName = id + MY_ROLE_SUFFIX;
// this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkTypeName, myRollName, null);
// this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, myRollName, portTypeQName);
// 
// GpelReceive receive = new GpelReceive(this.bpelNS, partnerLinkName, portTypeQName, operationName);
// String variableName = id + INPUT_SUFFIX;
// this.process.addMessageVariable(variableName, WSConstants.XSD_NS, variableName);
// receive.setGpelVariableName(variableName);
// sequence.addActivity(receive);
// }
// 
// private void addBlock(BlockNode blockNode, Collection<Node> parentBlock, GpelSequence sequence)
// throws GraphException {
// 
// //
// // normal block
// //
// EndBlockNode endBlockNode = getEndBlockNode(blockNode);
// GpelSequence normalSequence = createBlockSequence(blockNode, endBlockNode, true, parentBlock);
// GpelScope scope = new GpelScope(this.bpelNS, normalSequence);
// 
// //
// // exception block
// //
// // GpelSequence compensationSequence = createBlockSequence(blockNode,
// // endBlockNode, false, parentBlock);
// // TODO GpelExceptionHandler handler
// // = new GpelExceptionHandler(compensationSequence);
// // scope.add(handler);
// 
// sequence.addActivity(scope);
// }
// 
// private GpelSequence createBlockSequence(BlockNode blockNode, EndBlockNode endBlockNode, boolean blockBlock,
// Collection<Node> parentBlock) throws GraphException {
// Set<Node> block = getBlockBlock(blockNode, blockBlock);
// parentBlock.removeAll(block);
// GpelSequence sequence = new GpelSequence(this.bpelNS);
// addBlock(block, sequence);
// 
// // Create a copy to global variable.
// List<DataPort> outputPorts = endBlockNode.getOutputPorts();
// ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>();
// for (int i = 0; i < outputPorts.size(); i++) {
// DataPort outputPort = outputPorts.get(i);
// String variable = outputPort.getID() + OUTPUT_SUFFIX;
// int index = blockBlock ? i : i + outputPorts.size();
// DataPort inputPort = endBlockNode.getInputPort(index);
// Port fromPort = inputPort.getFromPort();
// GpelAssignCopyFrom from = createAssignCopyFrom(fromPort);
// GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS);
// to.setVariable(variable);
// GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to);
// copies.add(copy);
// }
// GpelAssign assign = new GpelAssign(this.bpelNS, copies);
// sequence.addActivity(assign);
// 
// return sequence;
// }
private Set<Node> getBlockBlock(Node node, boolean blockBlock) throws GraphException {
    Set<Node> block = new HashSet<Node>();
    int index = blockBlock ? 0 : 1;
    Port controlOutPort = node.getControlOutPorts().get(index);
    for (Node nextNode : controlOutPort.getToNodes()) {
        block.add(nextNode);
        getSpecialBlock(nextNode, 0, block, BlockNode.class, EndBlockNode.class);
    }
    return block;
}
Also used : InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) BlockNode(org.apache.airavata.workflow.model.graph.system.BlockNode) IfNode(org.apache.airavata.workflow.model.graph.system.IfNode) EndBlockNode(org.apache.airavata.workflow.model.graph.system.EndBlockNode) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode) Node(org.apache.airavata.workflow.model.graph.Node) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) ConstantNode(org.apache.airavata.workflow.model.graph.system.ConstantNode) EndifNode(org.apache.airavata.workflow.model.graph.system.EndifNode) OutputNode(org.apache.airavata.workflow.model.graph.system.OutputNode) Port(org.apache.airavata.workflow.model.graph.Port) ComponentPort(org.apache.airavata.workflow.model.component.ComponentPort) WSComponentPort(org.apache.airavata.workflow.model.component.ws.WSComponentPort) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) HashSet(java.util.HashSet)

Example 38 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class BPELScript method validate.

/**
 * @param warnings
 *            returns the warning messages.
 * @return true if the workflow is valid; false otherwise.
 */
public boolean validate(List<String> warnings) {
    // Empty
    if (this.graph.getNodes().size() == 0) {
        String message = "The workflow is empty.";
        warnings.add(message);
    }
    // Input ports need to be connected.
    Collection<Port> inputPorts = GraphUtil.getPorts(this.graph, Port.Kind.DATA_IN);
    for (Port inputPort : inputPorts) {
        ComponentPort componentPort = inputPort.getComponentPort();
        if (componentPort instanceof WSComponentPort) {
            WSComponentPort wsComponentPort = (WSComponentPort) componentPort;
            if (wsComponentPort.isOptional()) {
                // optional input.
                continue;
            }
        }
        Collection<Port> fromPorts = inputPort.getFromPorts();
        if (fromPorts.size() == 0) {
            Node node = inputPort.getNode();
            String message = node.getID() + " has an unconnected input " + inputPort.getName();
            warnings.add(message);
        }
    }
    // Input nodes need to be connected.
    List<InputNode> inputNodes = GraphUtil.getNodes(this.graph, InputNode.class);
    for (InputNode inputNode : inputNodes) {
        if (inputNode.getPort().getToPorts().size() == 0) {
            String message = inputNode.getID() + " is not connected to any service.";
            warnings.add(message);
        }
    }
    // Cycle
    if (GraphUtil.containsCycle(this.graph)) {
        String message = "There is a cycle in the workflow.";
        warnings.add(message);
    }
    // XXX bypass some checks for debugging.
    String debug = System.getProperty("xbaya.debug");
    if (!"true".equalsIgnoreCase(debug)) {
        // split/merge are not supported.
        List<ForEachNode> splitNodes = GraphUtil.getNodes(this.graph, ForEachNode.class);
        List<EndForEachNode> mergeNodes = GraphUtil.getNodes(this.graph, EndForEachNode.class);
        if (splitNodes.size() > 0 || mergeNodes.size() > 0) {
            String message = "Split/merge are not supported yet.";
            warnings.add(message);
        }
        // block are not supported.
        List<BlockNode> blockNodes = GraphUtil.getNodes(this.graph, BlockNode.class);
        List<EndBlockNode> endBlockNodes = GraphUtil.getNodes(this.graph, EndBlockNode.class);
        if (blockNodes.size() > 0 || endBlockNodes.size() > 0) {
            String message = "Blocks/EndBlocks are not supported yet.";
            warnings.add(message);
        }
    // // receive is not supported.
    // List<ReceiveNode> receiveNodes = GraphUtil.getNodes(this.graph,
    // ReceiveNode.class);
    // if (receiveNodes.size() > 0) {
    // String message = "Receive is not supported yet.";
    // warnings.add(message);
    // }
    }
    if (warnings.size() > 0) {
        return false;
    } else {
        // No error.
        return true;
    }
}
Also used : BlockNode(org.apache.airavata.workflow.model.graph.system.BlockNode) EndBlockNode(org.apache.airavata.workflow.model.graph.system.EndBlockNode) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) Port(org.apache.airavata.workflow.model.graph.Port) ComponentPort(org.apache.airavata.workflow.model.component.ComponentPort) WSComponentPort(org.apache.airavata.workflow.model.component.ws.WSComponentPort) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) BlockNode(org.apache.airavata.workflow.model.graph.system.BlockNode) IfNode(org.apache.airavata.workflow.model.graph.system.IfNode) EndBlockNode(org.apache.airavata.workflow.model.graph.system.EndBlockNode) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode) Node(org.apache.airavata.workflow.model.graph.Node) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) ConstantNode(org.apache.airavata.workflow.model.graph.system.ConstantNode) EndifNode(org.apache.airavata.workflow.model.graph.system.EndifNode) OutputNode(org.apache.airavata.workflow.model.graph.system.OutputNode) ComponentPort(org.apache.airavata.workflow.model.component.ComponentPort) WSComponentPort(org.apache.airavata.workflow.model.component.ws.WSComponentPort) WSComponentPort(org.apache.airavata.workflow.model.component.ws.WSComponentPort) EndBlockNode(org.apache.airavata.workflow.model.graph.system.EndBlockNode) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode)

Example 39 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class BPELScript method getIfBlock.

// private void addIf(IfNode ifNode, Collection<Node> parentBlock, GpelSequence sequence) throws GraphException {
// //
// // Condition
// //
// String booleanExpression = ifNode.getXPath();
// if (booleanExpression == null) {
// throw new GraphException("XPath cannot be null");
// }
// // replace $1, $2,... with actual value.
// List<? extends Port> inputPorts = ifNode.getInputPorts();
// ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>();
// for (int i = 0; i < inputPorts.size(); i++) {
// Port port = inputPorts.get(i);
// Port fromPort = port.getFromPort();
// if (fromPort != null) {
// String variableName = port.getID() + INPUT_SUFFIX;
// 
// GpelVariable ifVar = new GpelVariable(this.process.xml().getNamespace(), variableName);
// XmlNamespace xsdNS = process.xml().lookupNamespaceByName(WSConstants.XSD_NS_URI);
// if (null != xsdNS && xsdNS.getPrefix() != null) {
// ifVar.xml().setAttributeValue("element",
// xsdNS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart());
// } else {
// this.process.xml().declareNamespace(WSConstants.XSD_NS);
// ifVar.xml().setAttributeValue("element",
// WSConstants.XSD_NS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart());
// }
// this.process.getVariables().addVariable(ifVar);
// 
// GpelAssignCopyFrom from = createAssignCopyFrom(fromPort);
// GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS);
// to.setVariable(variableName);
// GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to);
// copies.add(copy);
// 
// booleanExpression = booleanExpression.replaceAll("\\$" + i, "\\$" + variableName);
// }
// }
// if (copies.size() > 0) {
// GpelAssign assign = new GpelAssign(this.bpelNS, copies);
// sequence.addActivity(assign);
// }
// GpelCondition condition = new GpelCondition(this.bpelNS, booleanExpression);
// 
// //
// // If block
// //
// EndifNode endifNode = getEndifNode(ifNode);
// GpelSequence ifSequence = createIfSequence(ifNode, endifNode, true, parentBlock);
// GpelIf gpelIf = new GpelIf(this.bpelNS, condition, ifSequence);
// 
// //
// // Else block
// //
// GpelSequence elseSequence = createIfSequence(ifNode, endifNode, false, parentBlock);
// GpelElse gpelElse = new GpelElse(this.bpelNS, elseSequence);
// gpelIf.setElse(gpelElse);
// 
// //
// // Create global variables for endif.
// //
// for (Port outputPort : endifNode.getOutputPorts()) {
// String variable = outputPort.getID() + OUTPUT_SUFFIX;
// GpelVariable ifVar = new GpelVariable(this.process.xml().getNamespace(), variable);
// XmlNamespace xsdNS = process.xml().lookupNamespaceByName(WSConstants.XSD_NS_URI);
// if (null != xsdNS && xsdNS.getPrefix() != null) {
// ifVar.xml().setAttributeValue("element",
// xsdNS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart());
// } else {
// this.process.xml().declareNamespace(WSConstants.XSD_NS);
// ifVar.xml().setAttributeValue("element",
// WSConstants.XSD_NS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart());
// }
// this.process.getVariables().addVariable(ifVar);
// }
// 
// sequence.addActivity(gpelIf);
// }
// 
// private GpelSequence createIfSequence(IfNode ifNode, EndifNode endifNode, boolean ifBlock,
// Collection<Node> parentBlock) throws GraphException {
// Set<Node> block = getIfBlock(ifNode, ifBlock);
// parentBlock.removeAll(block);
// GpelSequence sequence = new GpelSequence(this.bpelNS);
// addBlock(block, sequence);
// 
// // Create a copy to global variable.
// List<DataPort> outputPorts = endifNode.getOutputPorts();
// ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>();
// for (int i = 0; i < outputPorts.size(); i++) {
// DataPort outputPort = outputPorts.get(i);
// String variable = outputPort.getID() + OUTPUT_SUFFIX;
// int index = ifBlock ? i : i + outputPorts.size();
// DataPort inputPort = endifNode.getInputPort(index);
// Port fromPort = inputPort.getFromPort();
// GpelAssignCopyFrom from = createAssignCopyFrom(fromPort);
// GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS);
// to.setVariable(variable);
// GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to);
// copies.add(copy);
// }
// GpelAssign assign = new GpelAssign(this.bpelNS, copies);
// sequence.addActivity(assign);
// 
// return sequence;
// }
private Set<Node> getIfBlock(Node node, boolean ifBlock) throws GraphException {
    Set<Node> block = new HashSet<Node>();
    int index = ifBlock ? 0 : 1;
    Port controlOutPort = node.getControlOutPorts().get(index);
    for (Node nextNode : controlOutPort.getToNodes()) {
        block.add(nextNode);
        getSpecialBlock(nextNode, 0, block, IfNode.class, EndifNode.class);
    }
    return block;
}
Also used : InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) BlockNode(org.apache.airavata.workflow.model.graph.system.BlockNode) IfNode(org.apache.airavata.workflow.model.graph.system.IfNode) EndBlockNode(org.apache.airavata.workflow.model.graph.system.EndBlockNode) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode) Node(org.apache.airavata.workflow.model.graph.Node) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) ConstantNode(org.apache.airavata.workflow.model.graph.system.ConstantNode) EndifNode(org.apache.airavata.workflow.model.graph.system.EndifNode) OutputNode(org.apache.airavata.workflow.model.graph.system.OutputNode) Port(org.apache.airavata.workflow.model.graph.Port) ComponentPort(org.apache.airavata.workflow.model.component.ComponentPort) WSComponentPort(org.apache.airavata.workflow.model.component.ws.WSComponentPort) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) HashSet(java.util.HashSet)

Example 40 with Node

use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.

the class GraphCanvas method selectNodes.

private void selectNodes(List<Node> nodes) {
    deselectNode();
    for (Node node : nodes) {
        NodeController.getGUI(node).setSelectedFlag(true);
        NodeController.getGUI(node).setDraggedFlag(true);
    }
    this.multipleSelectedNodes = nodes;
    notifyListeners(new GraphCanvasEvent(GraphCanvasEvent.GraphCanvasEventType.NODE_SELECTED, this, this.workflow));
}
Also used : InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode)

Aggregations

Node (org.apache.airavata.workflow.model.graph.Node)74 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)46 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)40 DataPort (org.apache.airavata.workflow.model.graph.DataPort)31 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)24 Port (org.apache.airavata.workflow.model.graph.Port)20 OutputNode (org.apache.airavata.workflow.model.graph.system.OutputNode)20 StreamSourceNode (org.apache.airavata.workflow.model.graph.system.StreamSourceNode)18 EndForEachNode (org.apache.airavata.workflow.model.graph.system.EndForEachNode)16 ForEachNode (org.apache.airavata.workflow.model.graph.system.ForEachNode)16 MemoNode (org.apache.airavata.workflow.model.graph.system.MemoNode)15 NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)14 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)14 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)13 ConstantNode (org.apache.airavata.workflow.model.graph.system.ConstantNode)12 EndifNode (org.apache.airavata.workflow.model.graph.system.EndifNode)12 IfNode (org.apache.airavata.workflow.model.graph.system.IfNode)12 GraphException (org.apache.airavata.workflow.model.graph.GraphException)11 LinkedList (java.util.LinkedList)9 ArrayList (java.util.ArrayList)8