Search in sources :

Example 36 with AiravataException

use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.

the class XMLUtil method validate.

/**
 * Validates a specified XmlObject along with logging errors if any.
 *
 * @param xmlObject
 */
public static void validate(XmlObject xmlObject) throws AiravataException {
    XmlOptions validateOptions = new XmlOptions();
    ArrayList errorList = new ArrayList();
    validateOptions.setErrorListener(errorList);
    boolean isValid = xmlObject.validate(validateOptions);
    if (isValid) {
        // Valid
        return;
    }
    // Error
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < errorList.size(); i++) {
        XmlError error = (XmlError) errorList.get(i);
        logger.warn("Message: " + error.getMessage());
        logger.warn("Location of invalid XML: " + error.getCursorLocation().xmlText());
        stringBuilder.append("Message:" + error.getMessage());
        stringBuilder.append("Location of invalid XML: " + error.getCursorLocation().xmlText());
    }
    throw new AiravataException(stringBuilder.toString());
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) XmlError(org.apache.xmlbeans.XmlError) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 37 with AiravataException

use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.

the class Factory method initPrcessLaunchSubscriber.

public static synchronized void initPrcessLaunchSubscriber(MessageHandler processMessageHandler) throws AiravataException {
    if (getProcessLaunchSubscriber() != null)
        throw new AiravataException("Process launch Subscriber is already initialized");
    List<String> routingKeys = new ArrayList<>();
    routingKeys.add(ServerSettings.getRabbitmqProcessExchangeName());
    processLaunchSubscriber = MessagingFactory.getSubscriber(processMessageHandler, routingKeys, Type.PROCESS_LAUNCH);
}
Also used : ArrayList(java.util.ArrayList) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 38 with AiravataException

use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.

the class GFacEngineImpl method populateProcessContext.

@Override
public ProcessContext populateProcessContext(String processId, String gatewayId, String tokenId) throws GFacException, CredentialStoreException {
    // NOTE: Process context gives precedence to data come with process Computer resources;
    ProcessContext processContext = null;
    ProcessContext.ProcessContextBuilder builder = new ProcessContext.ProcessContextBuilder(processId, gatewayId, tokenId);
    try {
        AppCatalog appCatalog = Factory.getDefaultAppCatalog();
        ExperimentCatalog expCatalog = Factory.getDefaultExpCatalog();
        ProcessModel processModel = (ProcessModel) expCatalog.get(ExperimentCatalogModelType.PROCESS, processId);
        builder.setAppCatalog(appCatalog).setExperimentCatalog(expCatalog).setCuratorClient(Factory.getCuratorClient()).setStatusPublisher(Factory.getStatusPublisher()).setProcessModel(processModel).setGatewayResourceProfile(appCatalog.getGatewayProfile().getGatewayProfile(gatewayId)).setGatewayComputeResourcePreference(appCatalog.getGatewayProfile().getComputeResourcePreference(gatewayId, processModel.getComputeResourceId())).setGatewayStorageResourcePreference(appCatalog.getGatewayProfile().getStoragePreference(gatewayId, processModel.getStorageResourceId()));
        processContext = builder.build();
        /* check point */
        checkpoint(processContext);
        if (processModel.isUseUserCRPref()) {
            setUserResourceProfile(gatewayId, processContext);
            setUserComputeResourcePreference(gatewayId, processContext);
        }
        String scratchLocation = processContext.getScratchLocation();
        String workingDirectory = scratchLocation + File.separator + processId + File.separator;
        StorageResourceDescription storageResource = appCatalog.getStorageResource().getStorageResource(processModel.getStorageResourceId());
        if (storageResource != null) {
            processContext.setStorageResource(storageResource);
        } else {
            // we need to fail the process which will fail the experiment
            processContext.setProcessStatus(new ProcessStatus(ProcessState.FAILED));
            GFacUtils.saveAndPublishProcessStatus(processContext);
            throw new GFacException("expId: " + processModel.getExperimentId() + ", processId: " + processId + ":- Couldn't find storage resource for storage resource id :" + processModel.getStorageResourceId());
        }
        /*            StorageResourceDescription storageResource = appCatalog.getStorageResource().getStorageResource(processModel.getStorageResourceId());
            if (storageResource != null){
                processContext.setStorageResource(storageResource);
            }*/
        processContext.setComputeResourceDescription(appCatalog.getComputeResource().getComputeResource(processContext.getComputeResourceId()));
        processContext.setApplicationDeploymentDescription(appCatalog.getApplicationDeployment().getApplicationDeployement(processModel.getApplicationDeploymentId()));
        ApplicationInterfaceDescription applicationInterface = appCatalog.getApplicationInterface().getApplicationInterface(processModel.getApplicationInterfaceId());
        processContext.setApplicationInterfaceDescription(applicationInterface);
        List<OutputDataObjectType> applicationOutputs = applicationInterface.getApplicationOutputs();
        if (applicationOutputs != null && !applicationOutputs.isEmpty()) {
            for (OutputDataObjectType outputDataObjectType : applicationOutputs) {
                if (outputDataObjectType.getType().equals(DataType.STDOUT)) {
                    if (outputDataObjectType.getValue() == null || outputDataObjectType.getValue().equals("")) {
                        outputDataObjectType.setValue(workingDirectory + applicationInterface.getApplicationName() + ".stdout");
                        processContext.setStdoutLocation(workingDirectory + applicationInterface.getApplicationName() + ".stdout");
                    } else {
                        processContext.setStdoutLocation(outputDataObjectType.getValue());
                    }
                }
                if (outputDataObjectType.getType().equals(DataType.STDERR)) {
                    if (outputDataObjectType.getValue() == null || outputDataObjectType.getValue().equals("")) {
                        String stderrLocation = workingDirectory + applicationInterface.getApplicationName() + ".stderr";
                        outputDataObjectType.setValue(stderrLocation);
                        processContext.setStderrLocation(stderrLocation);
                    } else {
                        processContext.setStderrLocation(outputDataObjectType.getValue());
                    }
                }
            }
        }
        expCatalog.update(ExperimentCatalogModelType.PROCESS, processModel, processId);
        processModel.setProcessOutputs(applicationOutputs);
        if (processContext.getJobSubmissionProtocol() == JobSubmissionProtocol.UNICORE) {
            // process monitor mode set in getResourceJobManager method, but unicore doesn't have resource job manager.
            // hence we set process monitor mode here.
            processContext.setMonitorMode(MonitorMode.FORK);
        } else {
            processContext.setResourceJobManager(getResourceJobManager(processContext));
            processContext.setJobSubmissionRemoteCluster(Factory.getJobSubmissionRemoteCluster(processContext));
            processContext.setDataMovementRemoteCluster(Factory.getDataMovementRemoteCluster(processContext));
        }
        String inputPath = ServerSettings.getLocalDataLocation();
        if (inputPath != null) {
            processContext.setLocalWorkingDir((inputPath.endsWith("/") ? inputPath : inputPath + "/") + processContext.getProcessId());
        }
        List<Object> jobModels = expCatalog.get(ExperimentCatalogModelType.JOB, "processId", processId);
        if (jobModels != null && !jobModels.isEmpty()) {
            if (jobModels.size() > 1) {
                log.warn("Process has more than one job model, take first one");
            }
            processContext.setJobModel(((JobModel) jobModels.get(0)));
        }
        return processContext;
    } catch (AppCatalogException e) {
        String msg = "App catalog access exception ";
        saveErrorModel(processContext, e, msg);
        updateProcessFailure(processContext, msg);
        throw new GFacException(msg, e);
    } catch (RegistryException e) {
        String msg = "Registry access exception";
        saveErrorModel(processContext, e, msg);
        updateProcessFailure(processContext, msg);
        throw new GFacException(msg, e);
    } catch (AiravataException e) {
        String msg = "Remote cluster initialization error";
        saveErrorModel(processContext, e, msg);
        updateProcessFailure(processContext, msg);
        throw new GFacException(msg, e);
    }
}
Also used : ProcessModel(org.apache.airavata.model.process.ProcessModel) ExperimentCatalog(org.apache.airavata.registry.cpi.ExperimentCatalog) ProcessStatus(org.apache.airavata.model.status.ProcessStatus) AppCatalog(org.apache.airavata.registry.cpi.AppCatalog) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) StorageResourceDescription(org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription) GFacException(org.apache.airavata.gfac.core.GFacException) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) ApplicationInterfaceDescription(org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription) JobModel(org.apache.airavata.model.job.JobModel) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 39 with AiravataException

use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.

the class WorkflowInterpreter method taskOutputChanged.

@Subscribe
public void taskOutputChanged(TaskOutputChangeEvent taskOutputEvent) {
    String taskId = taskOutputEvent.getTaskIdentity().getTaskId();
    if (isTaskAwaiting(taskId)) {
        ProcessState state = ProcessState.COMPLETED;
        Node node = getAwaitingNodeForTask(taskId);
        List<OutputDataObjectType> applicationOutputs = taskOutputEvent.getOutput();
        Map<String, String> outputData = new HashMap<String, String>();
        for (OutputDataObjectType outputObj : applicationOutputs) {
            List<DataPort> outputPorts = node.getOutputPorts();
            for (DataPort dataPort : outputPorts) {
                if (dataPort.getName().equals(outputObj.getName())) {
                    outputData.put(outputObj.getName(), outputObj.getValue());
                }
            }
        }
        nodeOutputData.put(node, outputData);
        setupNodeDetailsOutput(node);
        node.setState(NodeExecutionState.FINISHED);
        try {
            publishNodeStatusChange(WorkflowNodeState.COMPLETED, node.getID(), experiment.getExperimentID());
            updateWorkflowNodeStatus(nodeInstanceList.get(node), state);
        } catch (RegistryException e) {
            log.error(e.getMessage(), e);
        } catch (AiravataException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : ProcessState(org.apache.airavata.model.status.ProcessState) DataPort(org.apache.airavata.workflow.model.graph.DataPort) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) Subscribe(com.google.common.eventbus.Subscribe)

Example 40 with AiravataException

use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.

the class WorkflowInterpreter method scheduleDynamically.

/**
 * @throws WorkflowException
 * @throws RegistryException
 */
public void scheduleDynamically() throws WorkflowException, RegistryException, AiravataException {
    try {
        this.getWorkflow().setExecutionState(WorkflowExecutionState.RUNNING);
        ArrayList<Node> inputNodes = this.getInputNodesDynamically();
        List<InputDataObjectType> experimentInputs = experiment.getExperimentInputs();
        Map<String, String> inputDataStrings = new HashMap<String, String>();
        for (InputDataObjectType dataObjectType : experimentInputs) {
            inputDataStrings.put(dataObjectType.getName(), dataObjectType.getValue());
        }
        for (Node node : inputNodes) {
            publishNodeStatusChange(WorkflowNodeState.EXECUTING, node.getID(), experiment.getExperimentID());
            if (inputDataStrings.containsKey(node.getID())) {
                ((InputNode) node).setDefaultValue(inputDataStrings.get(node.getID()));
            } else {
                log.warn("value for node not found " + node.getName());
            }
        }
        for (int i = 0; i < inputNodes.size(); ++i) {
            Node node = inputNodes.get(i);
            invokedNode.add(node);
            node.setState(NodeExecutionState.FINISHED);
            publishNodeStatusChange(WorkflowNodeState.INVOKED, node.getID(), experiment.getExperimentID());
            notifyViaInteractor(WorkflowExecutionMessage.NODE_STATE_CHANGED, null);
            String portId = ((InputNode) node).getID();
            Object portValue = ((InputNode) node).getDefaultValue();
            DataType dataType = ((InputNode) node).getDataType();
            // Saving workflow input Node data before running the workflow
            WorkflowNodeDetails workflowNode = createWorkflowNodeDetails(node);
            InputDataObjectType elem = new InputDataObjectType();
            elem.setName(portId);
            elem.setValue(portValue == null ? null : portValue.toString());
            elem.setType(dataType);
            workflowNode.addToNodeInputs(elem);
            getExperimentCatalog().update(ExperimentCatalogModelType.WORKFLOW_NODE_DETAIL, workflowNode, workflowNode.getNodeInstanceId());
            updateWorkflowNodeStatus(workflowNode, WorkflowNodeState.COMPLETED);
            publishNodeStatusChange(WorkflowNodeState.COMPLETED, node.getID(), experiment.getExperimentID());
        }
        while (this.getWorkflow().getExecutionState() != WorkflowExecutionState.STOPPED) {
            ArrayList<Thread> threadList = new ArrayList<Thread>();
            if (getRemainNodesDynamically() == 0) {
                notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_STATE_CHANGED, WorkflowExecutionState.STOPPED);
            }
            // ok we have paused sleep
            if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                log.info("Workflow execution " + experiment.getExperimentID() + " is paused.");
                while (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                    try {
                        Thread.sleep(400);
                    } catch (InterruptedException e) {
                        log.error(e.getMessage(), e);
                    }
                }
                if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
                    continue;
                }
                log.info("Workflow execution " + experiment.getExperimentID() + " is resumed.");
            }
            // get task list and execute them
            ArrayList<Node> readyNodes = this.getReadyNodesDynamically();
            for (final Node node : readyNodes) {
                if (node.isBreak()) {
                    this.notifyPause();
                    break;
                }
                if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED || this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
                    break;
                }
                WorkflowNodeDetails workflowNodeDetails = createWorkflowNodeDetails(node);
                // Since this is an independent node execution we can run these nodes in separate threads.
                Thread th = new Thread() {

                    public synchronized void run() {
                        try {
                            executeDynamically(node);
                        } catch (WorkflowException e) {
                            log.error("Error execution workflow Node : " + node.getID());
                            return;
                        } catch (TException e) {
                            log.error(e.getMessage(), e);
                        } catch (RegistryException e) {
                            log.error(e.getMessage(), e);
                        } catch (AiravataException e) {
                            log.error(e.getMessage(), e);
                        }
                    }
                };
                updateWorkflowNodeStatus(workflowNodeDetails, WorkflowNodeState.INVOKED);
                publishNodeStatusChange(WorkflowNodeState.INVOKED, node.getID(), experiment.getExperimentID());
                threadList.add(th);
                th.start();
                if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.STEP) {
                    this.getWorkflow().setExecutionState(WorkflowExecutionState.PAUSED);
                    // TODO update experiment state to suspend
                    break;
                }
            }
            // This thread waits until parallel nodes get finished to send the outputs dynamically.
            for (Thread th : threadList) {
                try {
                    th.join();
                } catch (InterruptedException e) {
                    // To change body of catch statement use File | Settings | File Templates.
                    e.printStackTrace();
                }
            }
            // Above statement set the nodeCount back to 0.
            // TODO commented this for foreach, fix this.
            sendOutputsDynamically();
            // Dry run sleep a lil bit to release load
            if (readyNodes.size() == 0) {
                // so we should pause the execution
                if (InterpreterUtil.getRunningNodeCountDynamically(this.getGraph()) == 0) /**
                 *&& InterpreterUtil.getFailedNodeCountDynamically(this.getGraph()) != 0*
                 */
                {
                    // Since airavata only support workflow interpreter server mode we do not want to keep thread in sleep mode
                    // continuously, so we make the workflow stop when there's nothing to do.
                    this.getWorkflow().setExecutionState(WorkflowExecutionState.STOPPED);
                }
                try {
                    Thread.sleep(400);
                } catch (InterruptedException e) {
                    log.error("Workflow Excecution is interrupted !");
                    return;
                }
            }
        }
        if (InterpreterUtil.getFailedNodeCountDynamically(this.getGraph()) == 0) {
            if (this.config.isActOnProvenance()) {
                try {
                    // this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager().setWorkflowInstanceStatus(
                    // this.config.getTopic(), this.config.getTopic(), State.FINISHED);
                    updateExperimentStatus(ExperimentState.COMPLETED);
                } catch (Exception e) {
                    throw new WorkflowException(e);
                }
            // System.out.println(this.config.getConfiguration().getJcrComponentRegistry().getExperimentCatalog().getWorkflowStatus(this.topic));
            }
        } else {
            if (this.config.isActOnProvenance()) {
                // this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager().
                // setWorkflowInstanceStatus(this.config.getTopic(),this.config.getTopic(), State.FAILED);
                updateExperimentStatus(ExperimentState.FAILED);
            }
        }
        UUID uuid = UUID.randomUUID();
        notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_TASK_START, new WorkflowInterpreterInteractor.TaskNotification("Stop Workflow", "Cleaning up resources for Workflow", uuid.toString()));
        // Send Notification for output values
        finish();
        // Sleep to provide for notification delay
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e);
        }
        notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_TASK_END, new WorkflowInterpreterInteractor.TaskNotification("Stop Workflow", "Cleaning up resources for Workflow", uuid.toString()));
    } catch (RuntimeException e) {
        // we reset all the state
        cleanup();
        raiseException(e);
    } finally {
        cleanup();
        this.getWorkflow().setExecutionState(WorkflowExecutionState.NONE);
        ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent(ExperimentState.COMPLETED, experiment.getExperimentId(), gatewayId);
        MessageContext msgCtx = new MessageContext(event, MessageType.EXPERIMENT, AiravataUtils.getId("EXPERIMENT"), gatewayId);
        msgCtx.setUpdatedTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
        publisher.publish(msgCtx);
    }
}
Also used : TException(org.apache.thrift.TException) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) Timestamp(java.sql.Timestamp) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) ExpCatChildDataType(org.apache.airavata.registry.cpi.ExpCatChildDataType) MessageContext(org.apache.airavata.messaging.core.MessageContext) AiravataException(org.apache.airavata.common.exception.AiravataException) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException)

Aggregations

AiravataException (org.apache.airavata.common.exception.AiravataException)40 IOException (java.io.IOException)10 TException (org.apache.thrift.TException)8 GFacException (org.apache.airavata.gfac.core.GFacException)6 RegistryException (org.apache.airavata.registry.cpi.RegistryException)6 XmlElement (org.xmlpull.infoset.XmlElement)5 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)4 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)4 MessagingException (javax.mail.MessagingException)3 MessageContext (org.apache.airavata.messaging.core.MessageContext)3 Session (com.jcraft.jsch.Session)2 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Flags (javax.mail.Flags)2 Message (javax.mail.Message)2 EmailParser (org.apache.airavata.gfac.core.monitor.EmailParser)2