Search in sources :

Example 1 with StorageClient

use of de.fzj.unicore.uas.client.StorageClient in project airavata by apache.

the class BESJobSubmissionTask method execute.

@Override
public TaskStatus execute(TaskContext taskContext) {
    TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
    StorageClient sc = null;
    ProcessContext processContext = taskContext.getParentProcessContext();
    // FIXME - use original output dir
    setInputOutputLocations(processContext);
    try {
        // con't reuse if UserDN has been changed.
        secProperties = getSecurityConfig(processContext);
    // try secProperties = secProperties.clone() if we can't use already initialized ClientConfigurations.
    } catch (GFacException e) {
        String msg = "Unicorn security context initialization error";
        log.error(msg, e);
        taskStatus.setState(TaskState.FAILED);
        taskStatus.setReason(msg);
        return taskStatus;
    }
    try {
        JobSubmissionProtocol protocol = processContext.getJobSubmissionProtocol();
        JobSubmissionInterface jobSubmissionInterface = GFacUtils.getPreferredJobSubmissionInterface(processContext);
        String factoryUrl = null;
        if (protocol.equals(JobSubmissionProtocol.UNICORE)) {
            UnicoreJobSubmission unicoreJobSubmission = GFacUtils.getUnicoreJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
            factoryUrl = unicoreJobSubmission.getUnicoreEndPointURL();
        }
        EndpointReferenceType eprt = EndpointReferenceType.Factory.newInstance();
        eprt.addNewAddress().setStringValue(factoryUrl);
        String userDN = processContext.getProcessModel().getUserDn();
        CreateActivityDocument cad = CreateActivityDocument.Factory.newInstance();
        // create storage
        StorageCreator storageCreator = new StorageCreator(secProperties, factoryUrl, 5, null);
        sc = storageCreator.createStorage();
        JobDefinitionType jobDefinition = JSDLGenerator.buildJSDLInstance(processContext, sc.getUrl()).getJobDefinition();
        cad.addNewCreateActivity().addNewActivityDocument().setJobDefinition(jobDefinition);
        log.info("Submitted JSDL: " + jobDefinition.getJobDescription());
        // copy files to local
        copyInputFilesToLocal(taskContext);
        // upload files if any
        DataTransferrer dt = new DataTransferrer(processContext, sc);
        dt.uploadLocalFiles();
        JobModel jobDetails = new JobModel();
        jobDetails.setTaskId(taskContext.getTaskId());
        jobDetails.setProcessId(taskContext.getProcessId());
        FactoryClient factory = new FactoryClient(eprt, secProperties);
        log.info("Activity Submitting to {} ... \n", factoryUrl);
        CreateActivityResponseDocument response = factory.createActivity(cad);
        log.info("Activity Submitted to {} ... \n", factoryUrl);
        EndpointReferenceType activityEpr = response.getCreateActivityResponse().getActivityIdentifier();
        log.info("Activity : " + activityEpr.getAddress().getStringValue() + " Submitted.");
        // factory.waitWhileActivityIsDone(activityEpr, 1000);
        jobId = WSUtilities.extractResourceID(activityEpr);
        if (jobId == null) {
            jobId = new Long(Calendar.getInstance().getTimeInMillis()).toString();
        }
        log.info("JobID: " + jobId);
        jobDetails.setJobId(jobId);
        jobDetails.setJobDescription(activityEpr.toString());
        jobDetails.setJobStatuses(Arrays.asList(new JobStatus(JobState.SUBMITTED)));
        processContext.setJobModel(jobDetails);
        GFacUtils.saveJobModel(processContext, jobDetails);
        GFacUtils.saveJobStatus(processContext, jobDetails);
        log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), factory.getActivityStatus(activityEpr).toString()));
        waitUntilDone(eprt, activityEpr, processContext, secProperties);
        ActivityStatusType activityStatus = null;
        activityStatus = getStatus(factory, activityEpr);
        log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), activityStatus.getState().toString()));
        ActivityClient activityClient;
        activityClient = new ActivityClient(activityEpr, secProperties);
        // now use the activity working directory property
        dt.setStorageClient(activityClient.getUspaceClient());
        List<OutputDataObjectType> copyOutput = null;
        if ((activityStatus.getState() == ActivityStateEnumeration.FAILED)) {
            String error = activityStatus.getFault().getFaultcode().getLocalPart() + "\n" + activityStatus.getFault().getFaultstring() + "\n EXITCODE: " + activityStatus.getExitCode();
            log.error(error);
            JobState applicationJobStatus = JobState.FAILED;
            jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
            sendNotification(processContext, jobDetails);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            // What if job is failed before execution and there are not stdouts generated yet?
            log.debug("Downloading any standard output and error files, if they were produced.");
            copyOutput = dt.downloadRemoteFiles();
        } else if (activityStatus.getState() == ActivityStateEnumeration.CANCELLED) {
            JobState applicationJobStatus = JobState.CANCELED;
            jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
            GFacUtils.saveJobStatus(processContext, jobDetails);
            throw new GFacException(processContext.getExperimentId() + "Job Canceled");
        } else if (activityStatus.getState() == ActivityStateEnumeration.FINISHED) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ignored) {
            }
            JobState applicationJobStatus = JobState.COMPLETE;
            jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
            GFacUtils.saveJobStatus(processContext, jobDetails);
            log.info("Job Id: {}, exit code: {}, exit status: {}", jobDetails.getJobId(), activityStatus.getExitCode(), ActivityStateEnumeration.FINISHED.toString());
            // if (activityStatus.getExitCode() == 0) {
            // } else {
            // dt.downloadStdOuts();
            // }
            copyOutput = dt.downloadRemoteFiles();
        }
        if (copyOutput != null) {
            copyOutputFilesToStorage(taskContext, copyOutput);
            for (OutputDataObjectType outputDataObjectType : copyOutput) {
                GFacUtils.saveExperimentOutput(processContext, outputDataObjectType.getName(), outputDataObjectType.getValue());
            }
        }
        // dt.publishFinalOutputs();
        taskStatus.setState(TaskState.COMPLETED);
    } catch (AppCatalogException e) {
        log.error("Error while retrieving UNICORE job submission..", e);
        taskStatus.setState(TaskState.FAILED);
    } catch (Exception e) {
        log.error("BES task failed... ", e);
        taskStatus.setState(TaskState.FAILED);
    }
    return taskStatus;
}
Also used : FactoryClient(de.fzj.unicore.bes.client.FactoryClient) JobSubmissionInterface(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface) EndpointReferenceType(org.w3.x2005.x08.addressing.EndpointReferenceType) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) JobStatus(org.apache.airavata.model.status.JobStatus) UnicoreJobSubmission(org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) JobDefinitionType(org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType) JobState(org.apache.airavata.model.status.JobState) JobModel(org.apache.airavata.model.job.JobModel) ActivityClient(de.fzj.unicore.bes.client.ActivityClient) JobSubmissionProtocol(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol) StorageClient(de.fzj.unicore.uas.client.StorageClient) TaskStatus(org.apache.airavata.model.status.TaskStatus) 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) GFacException(org.apache.airavata.gfac.core.GFacException)

Example 2 with StorageClient

use of de.fzj.unicore.uas.client.StorageClient in project airavata by apache.

the class AbstractSMSHandler method invoke.

@Override
public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
    try {
        initSecurityProperties(jobExecutionContext);
        JobSubmissionInterface preferredJobSubmissionInterface = jobExecutionContext.getPreferredJobSubmissionInterface();
        JobSubmissionProtocol protocol = preferredJobSubmissionInterface.getJobSubmissionProtocol();
        String interfaceId = preferredJobSubmissionInterface.getJobSubmissionInterfaceId();
        String factoryUrl = null;
        if (protocol.equals(JobSubmissionProtocol.UNICORE)) {
            UnicoreJobSubmission unicoreJobSubmission = GFacUtils.getUnicoreJobSubmission(interfaceId);
            factoryUrl = unicoreJobSubmission.getUnicoreEndPointURL();
        }
        storageClient = null;
        if (!isSMSInstanceExisting(jobExecutionContext)) {
            EndpointReferenceType eprt = EndpointReferenceType.Factory.newInstance();
            eprt.addNewAddress().setStringValue(factoryUrl);
            StorageCreator storageCreator = new StorageCreator(secProperties, factoryUrl, 5, null);
            try {
                storageClient = storageCreator.createStorage();
            } catch (Exception e2) {
                log.error("Cannot create storage..");
                throw new GFacHandlerException("Cannot create storage..", e2);
            }
            jobExecutionContext.setProperty(PROP_SMS_EPR, storageClient.getEPR());
        } else {
            EndpointReferenceType eprt = (EndpointReferenceType) jobExecutionContext.getProperty(PROP_SMS_EPR);
            try {
                storageClient = new StorageClient(eprt, secProperties);
            } catch (Exception e) {
                throw new GFacHandlerException("Cannot create storage..", e);
            }
        }
        dataTransferrer = new DataTransferrer(jobExecutionContext, storageClient);
    } catch (AppCatalogException e) {
        throw new GFacHandlerException("Error occurred while retrieving unicore job submission interface..", e);
    }
}
Also used : AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) EndpointReferenceType(org.w3.x2005.x08.addressing.EndpointReferenceType) DataTransferrer(org.apache.airavata.gfac.bes.utils.DataTransferrer) StorageClient(de.fzj.unicore.uas.client.StorageClient) StorageCreator(org.apache.airavata.gfac.bes.utils.StorageCreator) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GFacException(org.apache.airavata.gfac.core.GFacException) GFacHandlerException(org.apache.airavata.gfac.core.handler.GFacHandlerException) GFacHandlerException(org.apache.airavata.gfac.core.handler.GFacHandlerException)

Example 3 with StorageClient

use of de.fzj.unicore.uas.client.StorageClient in project airavata by apache.

the class StorageCreator method createStorage.

// The target site must have storage factory deployed with bes factory
public StorageClient createStorage() throws Exception {
    if (factoryUrl == null) {
        throw new Exception("Cannot create Storage Factory Url");
    }
    EndpointReferenceType sfEpr = WSUtilities.makeServiceEPR(factoryUrl, StorageFactory.SMF_PORT);
    String dn = findServerName(factoryUrl, sfEpr);
    WSUtilities.addServerIdentity(sfEpr, dn);
    secProps.getETDSettings().setReceiver(new X500Principal(dn));
    secProps.getETDSettings().setIssuerCertificateChain(secProps.getCredential().getCertificateChain());
    // TODO: remove it afterwards
    if (userName != null) {
        secProps.getETDSettings().getRequestedUserAttributes2().put("xlogin", new String[] { userName });
    }
    StorageFactoryClient sfc = new StorageFactoryClient(sfEpr, secProps);
    if (log.isDebugEnabled()) {
        log.debug("Using storage factory at <" + sfc.getUrl() + ">");
    }
    StorageClient sc = null;
    try {
        sc = sfc.createSMS(getCreateSMSDocument());
        String addr = sc.getEPR().getAddress().getStringValue();
        log.info(addr);
    } catch (Exception ex) {
        log.error("Could not create storage", ex);
        throw new Exception(ex);
    }
    return sc;
}
Also used : EndpointReferenceType(org.w3.x2005.x08.addressing.EndpointReferenceType) X500Principal(javax.security.auth.x500.X500Principal) StorageClient(de.fzj.unicore.uas.client.StorageClient) StorageFactoryClient(de.fzj.unicore.uas.client.StorageFactoryClient)

Example 4 with StorageClient

use of de.fzj.unicore.uas.client.StorageClient in project airavata by apache.

the class StorageCreator method createStorage.

// The target site must have storage factory deployed with bes factory
public StorageClient createStorage() throws Exception {
    if (factoryUrl == null) {
        throw new Exception("Cannot create Storage Factory Url");
    }
    EndpointReferenceType sfEpr = WSUtilities.makeServiceEPR(factoryUrl, StorageFactory.SMF_PORT);
    String dn = findServerName(factoryUrl, sfEpr);
    WSUtilities.addServerIdentity(sfEpr, dn);
    secProps.getETDSettings().setReceiver(new X500Principal(dn));
    secProps.getETDSettings().setIssuerCertificateChain(secProps.getCredential().getCertificateChain());
    // TODO: remove it afterwards
    if (userName != null) {
        secProps.getETDSettings().getRequestedUserAttributes2().put("xlogin", new String[] { userName });
    }
    StorageFactoryClient sfc = new StorageFactoryClient(sfEpr, secProps);
    if (log.isDebugEnabled()) {
        log.debug("Using storage factory at <" + sfc.getUrl() + ">");
    }
    StorageClient sc = null;
    try {
        sc = sfc.createSMS(getCreateSMSDocument());
        String addr = sc.getEPR().getAddress().getStringValue();
        log.info(addr);
    } catch (Exception ex) {
        log.error("Could not create storage", ex);
        throw new Exception(ex);
    }
    return sc;
}
Also used : EndpointReferenceType(org.w3.x2005.x08.addressing.EndpointReferenceType) X500Principal(javax.security.auth.x500.X500Principal) StorageClient(de.fzj.unicore.uas.client.StorageClient) StorageFactoryClient(de.fzj.unicore.uas.client.StorageFactoryClient)

Aggregations

StorageClient (de.fzj.unicore.uas.client.StorageClient)4 EndpointReferenceType (org.w3.x2005.x08.addressing.EndpointReferenceType)4 StorageFactoryClient (de.fzj.unicore.uas.client.StorageFactoryClient)2 X500Principal (javax.security.auth.x500.X500Principal)2 GFacException (org.apache.airavata.gfac.core.GFacException)2 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)2 JSchException (com.jcraft.jsch.JSchException)1 ActivityClient (de.fzj.unicore.bes.client.ActivityClient)1 FactoryClient (de.fzj.unicore.bes.client.FactoryClient)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 AiravataException (org.apache.airavata.common.exception.AiravataException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)1 DataTransferrer (org.apache.airavata.gfac.bes.utils.DataTransferrer)1 StorageCreator (org.apache.airavata.gfac.bes.utils.StorageCreator)1 SSHApiException (org.apache.airavata.gfac.core.SSHApiException)1 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)1 GFacHandlerException (org.apache.airavata.gfac.core.handler.GFacHandlerException)1 TaskException (org.apache.airavata.gfac.core.task.TaskException)1