Search in sources :

Example 1 with GFacHandlerException

use of org.apache.airavata.gfac.core.handler.GFacHandlerException in project airavata by apache.

the class SMSByteIOOutHandler method invoke.

@Override
public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
    super.invoke(jobExecutionContext);
    ActivityInfo activityInfo = (ActivityInfo) jobExecutionContext.getProperty(PROP_ACTIVITY_INFO);
    try {
        if (activityInfo == null) {
            log.error("No ActivityInfo instance found. The activity execution is ended due to an exception, see provider logs");
            return;
        }
        if ((activityInfo.getActivityStatus().getState() == ActivityStateEnumeration.FAILED)) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            try {
                dataTransferrer.downloadStdOuts();
            } catch (GFacProviderException e) {
                throw new GFacHandlerException("Cannot download stdout data", e);
            }
        } else if (activityInfo.getActivityStatus().getState() == ActivityStateEnumeration.FINISHED) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            try {
                if (activityInfo.getActivityStatus().getExitCode() == 0) {
                    dataTransferrer.downloadRemoteFiles();
                } else {
                    dataTransferrer.downloadStdOuts();
                }
            } catch (GFacProviderException e) {
                throw new GFacHandlerException("Cannot download stdout data", e);
            }
        }
    } finally {
        try {
            if (storageClient != null) {
                storageClient.destroy();
            }
        } catch (Exception e) {
            log.warn("Cannot destroy temporary SMS instance", e);
        }
    }
}
Also used : ActivityInfo(org.apache.airavata.gfac.bes.utils.ActivityInfo) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException) GFacHandlerException(org.apache.airavata.gfac.core.handler.GFacHandlerException) GFacHandlerException(org.apache.airavata.gfac.core.handler.GFacHandlerException) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException)

Example 2 with GFacHandlerException

use of org.apache.airavata.gfac.core.handler.GFacHandlerException 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 GFacHandlerException

use of org.apache.airavata.gfac.core.handler.GFacHandlerException in project airavata by apache.

the class AbstractSMSHandler method initSecurityProperties.

protected void initSecurityProperties(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
    log.debug("Initializing SMSInHandler security properties ..");
    if (secProperties != null) {
        secProperties = secProperties.clone();
        return;
    }
    UNICORESecurityContext unicoreContext;
    try {
        if (jobExecutionContext.getSecurityContext(X509SecurityContext.X509_SECURITY_CONTEXT) == null) {
            SecurityUtils.addSecurityContext(jobExecutionContext);
            log.info("Successfully added the UNICORE Security Context");
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        try {
            StringWriter errors = new StringWriter();
            e.printStackTrace(new PrintWriter(errors));
            GFacUtils.saveErrorDetails(jobExecutionContext, errors.toString(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.AIRAVATA_INTERNAL_ERROR);
        } catch (GFacException e1) {
            log.error(e1.getLocalizedMessage());
        }
        throw new GFacHandlerException("Error while creating UNICORESecurityContext", e, e.getLocalizedMessage());
    }
    try {
        unicoreContext = (UNICORESecurityContext) jobExecutionContext.getSecurityContext(X509SecurityContext.X509_SECURITY_CONTEXT);
        log.info("Successfully retrieved the UNICORE Security Context");
    } catch (GFacException e) {
        throw new GFacHandlerException(e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Generating client's default security configuration..");
    }
    // TODO: check what kind of credential (server signed or myproxy) should be used
    try {
        secProperties = unicoreContext.getDefaultConfiguration(false);
    } catch (Exception e) {
        throw new GFacHandlerException(e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Security properties are initialized.");
    }
    jobExecutionContext.setProperty(PROP_CLIENT_CONF, secProperties);
}
Also used : StringWriter(java.io.StringWriter) GFacException(org.apache.airavata.gfac.core.GFacException) UNICORESecurityContext(org.apache.airavata.gfac.bes.security.UNICORESecurityContext) 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) PrintWriter(java.io.PrintWriter)

Aggregations

GFacHandlerException (org.apache.airavata.gfac.core.handler.GFacHandlerException)3 GFacException (org.apache.airavata.gfac.core.GFacException)2 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)2 StorageClient (de.fzj.unicore.uas.client.StorageClient)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 UNICORESecurityContext (org.apache.airavata.gfac.bes.security.UNICORESecurityContext)1 ActivityInfo (org.apache.airavata.gfac.bes.utils.ActivityInfo)1 DataTransferrer (org.apache.airavata.gfac.bes.utils.DataTransferrer)1 StorageCreator (org.apache.airavata.gfac.bes.utils.StorageCreator)1 GFacProviderException (org.apache.airavata.gfac.core.provider.GFacProviderException)1 EndpointReferenceType (org.w3.x2005.x08.addressing.EndpointReferenceType)1