Search in sources :

Example 61 with GFacException

use of org.apache.airavata.gfac.core.GFacException 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 62 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class GFacWorker method run.

@Override
public void run() {
    try {
        ProcessState processState = processContext.getProcessState();
        switch(processState) {
            case CREATED:
            case VALIDATED:
            case STARTED:
                executeProcess();
                break;
            case PRE_PROCESSING:
            case CONFIGURING_WORKSPACE:
            case INPUT_DATA_STAGING:
            case EXECUTING:
            case MONITORING:
            case OUTPUT_DATA_STAGING:
            case POST_PROCESSING:
                if (continueTaskFlow) {
                    continueTaskExecution();
                } else {
                    recoverProcess();
                }
                break;
            case COMPLETED:
                completeProcess();
                break;
            case CANCELLING:
                cancelProcess();
                break;
            case CANCELED:
                // TODO - implement cancel scenario
                break;
            case FAILED:
                // TODO - implement failed scenario
                break;
            default:
                throw new GFacException("process Id : " + processId + " Couldn't identify process type");
        }
        if (processContext.isCancel()) {
            processState = processContext.getProcessState();
            switch(processState) {
                case MONITORING:
                case EXECUTING:
                    // don't send ack if the process is in MONITORING or EXECUTING states, wait until cancel email comes to airavata
                    break;
                case CANCELLING:
                    cancelProcess();
                    break;
                default:
                    sendAck();
                    Factory.getGfacContext().removeProcess(processContext.getProcessId());
                    break;
            }
        }
    } catch (GFacException e) {
        log.error("GFac Worker throws an exception", e);
        ProcessStatus status = new ProcessStatus(ProcessState.FAILED);
        status.setReason(e.getMessage());
        status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        processContext.setProcessStatus(status);
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        ErrorModel errorModel = new ErrorModel();
        errorModel.setUserFriendlyMessage("GFac Worker throws an exception");
        errorModel.setActualErrorMessage(errors.toString());
        errorModel.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
        try {
            GFacUtils.saveAndPublishProcessStatus(processContext);
            GFacUtils.saveExperimentError(processContext, errorModel);
            GFacUtils.saveProcessError(processContext, errorModel);
        } catch (GFacException e1) {
            log.error("expId: {}, processId: {} :- Couldn't save and publish process status {}", processContext.getExperimentId(), processContext.getProcessId(), processContext.getProcessState());
        }
        sendAck();
    }
}
Also used : ProcessState(org.apache.airavata.model.status.ProcessState) GFacException(org.apache.airavata.gfac.core.GFacException) StringWriter(java.io.StringWriter) ProcessStatus(org.apache.airavata.model.status.ProcessStatus) ErrorModel(org.apache.airavata.model.commons.ErrorModel) PrintWriter(java.io.PrintWriter)

Example 63 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class LocalRemoteCluster method copyTo.

@Override
public void copyTo(String localFile, String remoteFile) throws GFacException {
    Path sourcePath = Paths.get(localFile);
    Path targetPath = Paths.get(remoteFile);
    try {
        Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        throw new GFacException("Error while copying sourceFile: " + sourcePath.toString() + ", to destinationFile: " + targetPath.toString(), e);
    }
}
Also used : Path(java.nio.file.Path) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException)

Example 64 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class LocalRemoteCluster method makeDirectory.

@Override
public void makeDirectory(String directoryPath) throws GFacException {
    Path dirPath = Paths.get(directoryPath);
    Set<PosixFilePermission> perms = new HashSet<>();
    // add permission as rwxr--r-- 744
    perms.add(PosixFilePermission.OWNER_WRITE);
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_EXECUTE);
    perms.add(PosixFilePermission.GROUP_READ);
    perms.add(PosixFilePermission.OTHERS_READ);
    FileAttribute<Set<PosixFilePermission>> fileAttributes = PosixFilePermissions.asFileAttribute(perms);
    try {
        Files.createDirectory(dirPath, fileAttributes);
    } catch (IOException e) {
        throw new GFacException("Error making directory", e);
    }
}
Also used : Path(java.nio.file.Path) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) PosixFilePermission(java.nio.file.attribute.PosixFilePermission)

Example 65 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class BESJobSubmissionTask method cancelJob.

/**
 * EndpointReference need to be saved to make cancel work.
 *
 * @param processContext
 * @throws GFacException
 */
public boolean cancelJob(ProcessContext processContext) throws GFacException {
    try {
        String activityEpr = processContext.getJobModel().getJobDescription();
        // initSecurityProperties(processContext);
        EndpointReferenceType eprt = EndpointReferenceType.Factory.parse(activityEpr);
        JobSubmissionProtocol protocol = processContext.getJobSubmissionProtocol();
        String interfaceId = processContext.getApplicationInterfaceDescription().getApplicationInterfaceId();
        String factoryUrl = null;
        if (protocol.equals(JobSubmissionProtocol.UNICORE)) {
            UnicoreJobSubmission unicoreJobSubmission = GFacUtils.getUnicoreJobSubmission(interfaceId);
            factoryUrl = unicoreJobSubmission.getUnicoreEndPointURL();
        }
        EndpointReferenceType epr = EndpointReferenceType.Factory.newInstance();
        epr.addNewAddress().setStringValue(factoryUrl);
        FactoryClient factory = new FactoryClient(epr, secProperties);
        factory.terminateActivity(eprt);
        return true;
    } catch (Exception e) {
        throw new GFacException(e.getLocalizedMessage(), e);
    }
}
Also used : JobSubmissionProtocol(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol) UnicoreJobSubmission(org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission) FactoryClient(de.fzj.unicore.bes.client.FactoryClient) EndpointReferenceType(org.w3.x2005.x08.addressing.EndpointReferenceType) GFacException(org.apache.airavata.gfac.core.GFacException) URISyntaxException(java.net.URISyntaxException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) TaskException(org.apache.airavata.gfac.core.task.TaskException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) JSchException(com.jcraft.jsch.JSchException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) GFacException(org.apache.airavata.gfac.core.GFacException) SSHApiException(org.apache.airavata.gfac.core.SSHApiException) IOException(java.io.IOException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

GFacException (org.apache.airavata.gfac.core.GFacException)73 IOException (java.io.IOException)24 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)19 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)16 JSchException (com.jcraft.jsch.JSchException)15 RegistryException (org.apache.airavata.registry.cpi.RegistryException)15 AiravataException (org.apache.airavata.common.exception.AiravataException)14 TaskStatus (org.apache.airavata.model.status.TaskStatus)13 URISyntaxException (java.net.URISyntaxException)12 ErrorModel (org.apache.airavata.model.commons.ErrorModel)11 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)10 TException (org.apache.thrift.TException)9 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)8 DefaultClientConfiguration (eu.unicore.util.httpclient.DefaultClientConfiguration)7 URI (java.net.URI)7 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)7 Session (com.jcraft.jsch.Session)6 InvalidKeyException (java.security.InvalidKeyException)6 RemoteCluster (org.apache.airavata.gfac.core.cluster.RemoteCluster)6 JobModel (org.apache.airavata.model.job.JobModel)6