Search in sources :

Example 1 with AiravataException

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

the class GFacEngineImpl method executeCancel.

private void executeCancel(TaskContext taskContext, JobSubmissionTask jSTask) throws GFacException {
    try {
        JobStatus oldJobStatus = jSTask.cancel(taskContext);
        // If Job was in Queued state when cancel command runs, then there won't be any email from this job.
        ProcessContext pc = taskContext.getParentProcessContext();
        JobMonitor monitorService = Factory.getMonitorService(pc.getMonitorMode());
        monitorService.canceledJob(pc.getJobModel().getJobId());
    } catch (TaskException e) {
        throw new GFacException("Error while cancelling job");
    } catch (AiravataException e) {
        throw new GFacException("Error wile getting monitoring service");
    }
}
Also used : JobStatus(org.apache.airavata.model.status.JobStatus) TaskException(org.apache.airavata.gfac.core.task.TaskException) GFacException(org.apache.airavata.gfac.core.GFacException) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) JobMonitor(org.apache.airavata.gfac.core.monitor.JobMonitor) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 2 with AiravataException

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

the class GFacEngineImpl method executeJobMonitoring.

private void executeJobMonitoring(TaskContext taskContext, boolean recovery) throws GFacException {
    ProcessContext processContext = taskContext.getParentProcessContext();
    TaskStatus taskStatus;
    JobMonitor monitorService = null;
    try {
        taskStatus = new TaskStatus(TaskState.EXECUTING);
        taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        taskContext.setTaskStatus(taskStatus);
        GFacUtils.saveAndPublishTaskStatus(taskContext);
        MonitorTaskModel monitorTaskModel = ((MonitorTaskModel) taskContext.getSubTaskModel());
        monitorService = Factory.getMonitorService(monitorTaskModel.getMonitorMode());
        if (!monitorService.isMonitoring(processContext.getJobModel().getJobId())) {
            monitorService.monitor(processContext.getJobModel().getJobId(), taskContext);
        } else {
            log.warn("Jobid: {}, already in monitoring map", processContext.getJobModel().getJobId());
        }
    } catch (AiravataException | TException e) {
        taskStatus = new TaskStatus(TaskState.FAILED);
        taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        taskStatus.setReason("Couldn't handover jobId {} to monitor service, monitor service type {}");
        taskContext.setTaskStatus(taskStatus);
        GFacUtils.saveAndPublishTaskStatus(taskContext);
        String errorMsg = new StringBuilder("expId: ").append(processContext.getExperimentId()).append(", processId: ").append(processContext.getProcessId()).append(", taskId: ").append(taskContext.getTaskId()).append(", type: ").append(taskContext.getTaskType().name()).append(" :- Input staging failed. Reason: ").append(taskStatus.getReason()).toString();
        ErrorModel errorModel = new ErrorModel();
        errorModel.setUserFriendlyMessage("Error while staging output data");
        errorModel.setActualErrorMessage(errorMsg);
        GFacUtils.saveTaskError(taskContext, errorModel);
        throw new GFacException(e);
    }
    if (processContext.isPauseTaskExecution()) {
        // we won't update task status to complete, job monitor will update task status to complete after it complete monitoring for this job id.
        return;
    }
    taskStatus = new TaskStatus(TaskState.COMPLETED);
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskStatus.setReason("Successfully handed over job id to job monitor service.");
    taskContext.setTaskStatus(taskStatus);
    GFacUtils.saveAndPublishTaskStatus(taskContext);
}
Also used : TException(org.apache.thrift.TException) GFacException(org.apache.airavata.gfac.core.GFacException) ErrorModel(org.apache.airavata.model.commons.ErrorModel) TaskStatus(org.apache.airavata.model.status.TaskStatus) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) JobMonitor(org.apache.airavata.gfac.core.monitor.JobMonitor) MonitorTaskModel(org.apache.airavata.model.task.MonitorTaskModel) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 3 with AiravataException

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

the class SCPDataStageTask method execute.

@Override
public TaskStatus execute(TaskContext taskContext) {
    TaskStatus status = new TaskStatus(TaskState.EXECUTING);
    AuthenticationInfo authenticationInfo = null;
    DataStagingTaskModel subTaskModel = null;
    String localDataDir = null;
    ProcessContext processContext = taskContext.getParentProcessContext();
    ProcessState processState = processContext.getProcessState();
    try {
        subTaskModel = ((DataStagingTaskModel) taskContext.getSubTaskModel());
        if (processState == ProcessState.OUTPUT_DATA_STAGING) {
            OutputDataObjectType processOutput = taskContext.getProcessOutput();
            if (processOutput != null && processOutput.getValue() == null) {
                log.error("expId: {}, processId:{}, taskId: {}:- Couldn't stage file {} , file name shouldn't be null", taskContext.getExperimentId(), taskContext.getProcessId(), taskContext.getTaskId(), processOutput.getName());
                status = new TaskStatus(TaskState.FAILED);
                if (processOutput.isIsRequired()) {
                    status.setReason("File name is null, but this output's isRequired bit is not set");
                } else {
                    status.setReason("File name is null");
                }
                return status;
            }
        } else if (processState == ProcessState.INPUT_DATA_STAGING) {
            InputDataObjectType processInput = taskContext.getProcessInput();
            if (processInput != null && processInput.getValue() == null) {
                log.error("expId: {}, processId:{}, taskId: {}:- Couldn't stage file {} , file name shouldn't be null", taskContext.getExperimentId(), taskContext.getProcessId(), taskContext.getTaskId(), processInput.getName());
                status = new TaskStatus(TaskState.FAILED);
                if (processInput.isIsRequired()) {
                    status.setReason("File name is null, but this input's isRequired bit is not set");
                } else {
                    status.setReason("File name is null");
                }
                return status;
            }
        } else {
            status.setState(TaskState.FAILED);
            status.setReason("Invalid task invocation, Support " + ProcessState.INPUT_DATA_STAGING.name() + " and " + "" + ProcessState.OUTPUT_DATA_STAGING.name() + " process phases. found " + processState.name());
            return status;
        }
        StorageResourceDescription storageResource = processContext.getStorageResource();
        // StoragePreference storagePreference = taskContext.getParentProcessContext().getStoragePreference();
        String hostName = null;
        if (storageResource != null) {
            hostName = storageResource.getHostName();
        } else {
            throw new GFacException("Storage Resource is null");
        }
        String inputPath = processContext.getStorageFileSystemRootLocation();
        inputPath = (inputPath.endsWith(File.separator) ? inputPath : inputPath + File.separator);
        // use rsync instead of scp if source and destination host and user name is same.
        URI sourceURI = new URI(subTaskModel.getSource());
        String fileName = sourceURI.getPath().substring(sourceURI.getPath().lastIndexOf(File.separator) + 1, sourceURI.getPath().length());
        Session remoteSession = Factory.getSSHSession(Factory.getComputerResourceSSHKeyAuthentication(processContext), processContext.getComputeResourceServerInfo());
        Session storageSession = Factory.getSSHSession(Factory.getStorageSSHKeyAuthentication(processContext), processContext.getStorageResourceServerInfo());
        URI destinationURI = null;
        if (subTaskModel.getDestination().startsWith("dummy")) {
            destinationURI = TaskUtils.getDestinationURI(taskContext, hostName, inputPath, fileName);
            subTaskModel.setDestination(destinationURI.toString());
        } else {
            destinationURI = new URI(subTaskModel.getDestination());
        }
        if (sourceURI.getHost().equalsIgnoreCase(destinationURI.getHost()) && sourceURI.getUserInfo().equalsIgnoreCase(destinationURI.getUserInfo())) {
            localDataCopy(taskContext, sourceURI, destinationURI);
            status.setState(TaskState.COMPLETED);
            status.setReason("Locally copied file using 'cp' command ");
            return status;
        }
        status = new TaskStatus(TaskState.COMPLETED);
        // Wildcard for file name. Has to find the correct name.
        if (fileName.contains("*")) {
            String destParentPath = (new File(destinationURI.getPath())).getParentFile().getPath();
            String sourceParentPath = (new File(sourceURI.getPath())).getParentFile().getPath();
            List<String> fileNames = taskContext.getParentProcessContext().getDataMovementRemoteCluster().getFileNameFromExtension(fileName, sourceParentPath, remoteSession);
            ExperimentCatalog experimentCatalog = processContext.getExperimentCatalog();
            String experimentId = processContext.getExperimentId();
            String processId = processContext.getProcessId();
            OutputDataObjectType processOutput = taskContext.getProcessOutput();
            for (int i = 0; i < fileNames.size(); i++) {
                String temp = fileNames.get(i);
                if (temp != null && temp != "") {
                    fileName = temp;
                }
                if (destParentPath.endsWith(File.separator)) {
                    destinationURI = new URI(destParentPath + fileName);
                } else {
                    destinationURI = new URI(destParentPath + File.separator + fileName);
                }
                // Wildcard support is only enabled for output data staging
                if (processState == ProcessState.OUTPUT_DATA_STAGING) {
                    processOutput.setName(fileName);
                    experimentCatalog.add(ExpCatChildDataType.EXPERIMENT_OUTPUT, Arrays.asList(processOutput), experimentId);
                    experimentCatalog.add(ExpCatChildDataType.PROCESS_OUTPUT, Arrays.asList(processOutput), processId);
                    taskContext.setProcessOutput(processOutput);
                    makeDir(taskContext, destinationURI);
                    // TODO - save updated subtask model with new destination
                    outputDataStaging(taskContext, remoteSession, sourceURI, storageSession, destinationURI);
                    status.setReason("Successfully staged output data");
                }
            }
            if (processState == ProcessState.OUTPUT_DATA_STAGING) {
                status.setReason("Successfully staged output data");
            } else {
                status.setReason("Wildcard support is only enabled for output data staging");
            }
        } else {
            if (processState == ProcessState.INPUT_DATA_STAGING) {
                inputDataStaging(taskContext, storageSession, sourceURI, remoteSession, destinationURI);
                status.setReason("Successfully staged input data");
            } else if (processState == ProcessState.OUTPUT_DATA_STAGING) {
                makeDir(taskContext, destinationURI);
                // TODO - save updated subtask model with new destination
                outputDataStaging(taskContext, remoteSession, sourceURI, storageSession, destinationURI);
                status.setReason("Successfully staged output data");
            }
        }
    } catch (TException e) {
        String msg = "Couldn't create subTask model thrift model";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
        return status;
    } catch (ApplicationSettingsException | FileNotFoundException e) {
        String msg = "Failed while reading credentials";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
    } catch (URISyntaxException e) {
        String msg = "Source or destination uri is not correct source : " + subTaskModel.getSource() + ", " + "destination : " + subTaskModel.getDestination();
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
    } catch (CredentialStoreException e) {
        String msg = "Storage authentication issue, could be invalid credential token";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
    } catch (AiravataException e) {
        String msg = "Error while creating ssh session with client";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
    } catch (JSchException | IOException e) {
        String msg = "Failed to do scp with client";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
    } catch (RegistryException | GFacException e) {
        String msg = "Data staging failed";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
    }
    return status;
}
Also used : TException(org.apache.thrift.TException) JSchException(com.jcraft.jsch.JSchException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ExperimentCatalog(org.apache.airavata.registry.cpi.ExperimentCatalog) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) URI(java.net.URI) AuthenticationInfo(org.apache.airavata.gfac.core.authentication.AuthenticationInfo) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) AiravataException(org.apache.airavata.common.exception.AiravataException) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) IOException(java.io.IOException) TaskStatus(org.apache.airavata.model.status.TaskStatus) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ProcessState(org.apache.airavata.model.status.ProcessState) StorageResourceDescription(org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription) GFacException(org.apache.airavata.gfac.core.GFacException) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) ErrorModel(org.apache.airavata.model.commons.ErrorModel) File(java.io.File) Session(com.jcraft.jsch.Session)

Example 4 with AiravataException

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

the class StreamData method runOutputStaging.

public void runOutputStaging() throws URISyntaxException, IllegalAccessException, InstantiationException, CredentialStoreException, AiravataException, IOException, JSchException {
    try {
        URI sourceURI = new URI(subTaskModel.getSource());
        String fileName = sourceURI.getPath().substring(sourceURI.getPath().lastIndexOf(File.separator) + 1, sourceURI.getPath().length());
        URI destinationURI = null;
        if (subTaskModel.getDestination().startsWith("dummy")) {
            destinationURI = getDestinationURI(taskContext, fileName);
            subTaskModel.setDestination(destinationURI.toString());
        } else {
            destinationURI = new URI(subTaskModel.getDestination());
        }
        if (sourceURI.getHost().equalsIgnoreCase(destinationURI.getHost()) && sourceURI.getUserInfo().equalsIgnoreCase(destinationURI.getUserInfo())) {
            localDataCopy(taskContext, sourceURI, destinationURI);
        }
        Session srcSession = Factory.getSSHSession(Factory.getComputerResourceSSHKeyAuthentication(taskContext.getParentProcessContext()), taskContext.getParentProcessContext().getComputeResourceServerInfo());
        Session destSession = Factory.getSSHSession(Factory.getStorageSSHKeyAuthentication(taskContext.getParentProcessContext()), taskContext.getParentProcessContext().getStorageResourceServerInfo());
        String targetPath = destinationURI.getPath().substring(0, destinationURI.getPath().lastIndexOf('/'));
        SSHUtils.makeDirectory(targetPath, destSession);
        outputDataStaging(taskContext, srcSession, sourceURI, destSession, destinationURI);
    } catch (GFacException e) {
        log.error("expId: {}, processId:{}, taskId: {}:- Couldn't stage file {} , Error while output staging", taskContext.getExperimentId(), taskContext.getProcessId(), taskContext.getTaskId(), taskContext.getProcessOutput().getName());
        throw new AiravataException("Error while output staging", e);
    }
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) URI(java.net.URI) Session(com.jcraft.jsch.Session) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 5 with AiravataException

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

the class ServerMain method main.

// private static void addSecondaryShutdownHook(){
// Runtime.getRuntime().addShutdownHook(new Thread(){
// @Override
// public void run() {
// System.out.print("Graceful shutdown attempt is still active. Do you want to exit instead? (y/n)");
// String command=System.console().readLine().trim().toLowerCase();
// if (command.equals("yes") || command.equals("y")){
// System.exit(1);
// }
// }
// });
// }
public static void main(String[] args) throws ParseException, IOException, AiravataException {
    ServerSettings.mergeSettingsCommandLineArgs(args);
    ServerSettings.setServerRoles(ApplicationSettings.getSetting(SERVERS_KEY, "all").split(","));
    if (ServerSettings.isEnabledKafkaLogging()) {
        final ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
        if (iLoggerFactory instanceof LoggerContext) {
            final KafkaAppender kafkaAppender = new KafkaAppender(ServerSettings.getKafkaBrokerList(), ServerSettings.getKafkaTopicPrefix());
            kafkaAppender.setContext((LoggerContext) iLoggerFactory);
            kafkaAppender.setName("kafka-appender");
            kafkaAppender.clearAllFilters();
            kafkaAppender.start();
            // Until AIRAVATA-2073 filter org.apache.kafka logs
            ((LoggerContext) iLoggerFactory).getLogger("org.apache.airavata").addAppender(kafkaAppender);
            ((LoggerContext) iLoggerFactory).getLogger("org.apache.zookeeper").addAppender(kafkaAppender);
            ((LoggerContext) iLoggerFactory).getLogger("org.apache.derby").addAppender(kafkaAppender);
            ((LoggerContext) iLoggerFactory).getLogger("org.apache.commons").addAppender(kafkaAppender);
            ((LoggerContext) iLoggerFactory).getLogger("org.apache.thrift").addAppender(kafkaAppender);
            ((LoggerContext) iLoggerFactory).getLogger("com").addAppender(kafkaAppender);
            ((LoggerContext) iLoggerFactory).getLogger("net").addAppender(kafkaAppender);
        } else {
            logger.warn("Kafka logging is enabled but cannot find logback LoggerContext, found", iLoggerFactory.getClass().toString());
            throw new AiravataException("Kafka logging is enabled but cannot find logback LoggerContext");
        }
    } else {
        logger.info("Kafka logging is disabled in airavata server configurations");
    }
    CommandLineParameters commandLineParameters = StringUtil.getCommandLineParser(args);
    if (commandLineParameters.getArguments().contains(STOP_COMMAND_STR)) {
        performServerStopRequest(commandLineParameters);
    } else {
        AiravataZKUtils.startEmbeddedZK(cnxnFactory);
        performServerStart(args);
    }
}
Also used : CommandLineParameters(org.apache.airavata.common.utils.StringUtil.CommandLineParameters) ILoggerFactory(org.slf4j.ILoggerFactory) KafkaAppender(org.apache.airavata.common.logging.kafka.KafkaAppender) LoggerContext(ch.qos.logback.classic.LoggerContext) AiravataException(org.apache.airavata.common.exception.AiravataException)

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