Search in sources :

Example 46 with GFacException

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

the class GfacServerHandler method submitProcess.

/**
 * * After creating the experiment Data and Task Data in the orchestrator
 * * Orchestrator has to invoke this operation for each Task per experiment to run
 * * the actual Job related actions.
 * *
 * * @param experimentID
 * * @param taskID
 * * @param gatewayId:
 * *  The GatewayId is inferred from security context and passed onto gfac.
 * * @return sucess/failure
 * *
 * *
 *
 * @param processId - processModel id in registry
 * @param gatewayId - gateway Identification
 */
public boolean submitProcess(String processId, String gatewayId, String tokenId) throws TException {
    MDC.put(MDCConstants.PROCESS_ID, processId);
    MDC.put(MDCConstants.GATEWAY_ID, gatewayId);
    MDC.put(MDCConstants.TOKEN_ID, tokenId);
    try {
        executorService.execute(MDCUtil.wrapWithMDC(new GFacWorker(processId, gatewayId, tokenId)));
    } catch (GFacException e) {
        log.error("Failed to submit process", e);
        throw new TException("Failed to submit process", e);
    } catch (CredentialStoreException e) {
        log.error("Failed to submit process due to credential issue, " + "make sure you are passing a valid credentials");
        throw new TException("Failed to submit process due to credential issue, " + "make sure you are passing a valid credential token", e);
    } catch (Exception e) {
        log.error("Error creating zookeeper nodes", e);
        throw new TException("Error creating zookeeper nodes", e);
    }
    return true;
}
Also used : TException(org.apache.thrift.TException) GFacException(org.apache.airavata.gfac.core.GFacException) GFacWorker(org.apache.airavata.gfac.impl.GFacWorker) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) AiravataStartupException(org.apache.airavata.common.exception.AiravataStartupException) GFacException(org.apache.airavata.gfac.core.GFacException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 47 with GFacException

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

the class DataTransferrer method uploadLocalFiles.

public void uploadLocalFiles() throws GFacException {
    List<String> inFilePrms = new ArrayList<>();
    // FIXME - remove hard coded file path.
    inFilePrms.addAll(extractInFileParams());
    // inFilePrms.add("file://home/airavata/test/hpcinput-localhost-uslims3_cauma3d-00950.tar");
    for (String uri : inFilePrms) {
        String fileName = new File(uri).getName();
        if (uri.startsWith("file")) {
            try {
                String uriWithoutProtocol = uri.substring(uri.lastIndexOf("://") + 2, uri.length());
                FileUploader fileUploader = new FileUploader(uriWithoutProtocol, fileName, Mode.overwrite, false);
                log.info("Uploading file {}", fileName);
                fileUploader.perform(storageClient);
            } catch (FileNotFoundException e3) {
                throw new GFacException("Error while staging-in, local file " + fileName + " not found", e3);
            } catch (Exception e) {
                throw new GFacException("Cannot upload files", e);
            }
        }
    }
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) ArrayList(java.util.ArrayList) GFacException(org.apache.airavata.gfac.core.GFacException) URISyntaxException(java.net.URISyntaxException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 48 with GFacException

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

the class DataTransferrer method downloadStdOuts.

public void downloadStdOuts() throws GFacException {
    String stdoutFileName = new File(stdoutLocation).getName();
    String stderrFileName = new File(stderrLocation).getName();
    FileDownloader f1 = null;
    log.info("Downloading stdout and stderr..");
    log.info(stdoutFileName + " -> " + stdoutLocation);
    f1 = new FileDownloader(stdoutFileName, stdoutLocation, Mode.overwrite);
    try {
        f1.perform(storageClient);
    // String stdoutput = readFile(stdoutLocation);
    } catch (Exception e) {
        log.error("Error while downloading " + stdoutFileName + " to location " + stdoutLocation, e);
    }
    log.info(stderrFileName + " -> " + stderrLocation);
    f1.setFrom(stderrFileName);
    f1.setTo(stderrLocation);
    try {
        f1.perform(storageClient);
    // String stderror = readFile(stderrLocation);
    } catch (Exception e) {
        log.error("Error while downloading " + stderrFileName + " to location " + stderrLocation);
    }
    String scriptExitCodeFName = "UNICORE_SCRIPT_EXIT_CODE";
    String scriptCodeLocation = gatewayDownloadLocation + File.separator + scriptExitCodeFName;
    if (UASDataStagingProcessor.isUnicoreEndpoint(processContext)) {
        f1.setFrom(scriptExitCodeFName);
        f1.setTo(scriptCodeLocation);
        try {
            f1.perform(storageClient);
            OutputDataObjectType output = new OutputDataObjectType();
            output.setName(scriptExitCodeFName);
            output.setValue(scriptCodeLocation);
            output.setType(DataType.URI);
            output.setIsRequired(true);
            processContext.getProcessModel().getProcessOutputs().add(output);
            log.info("UNICORE_SCRIPT_EXIT_CODE -> " + scriptCodeLocation);
            log.info("EXIT CODE: " + readFile(scriptCodeLocation));
        } catch (Exception e) {
            log.error("Error downloading file " + scriptExitCodeFName + " to location " + scriptCodeLocation, e);
        }
    }
}
Also used : OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) GFacException(org.apache.airavata.gfac.core.GFacException) URISyntaxException(java.net.URISyntaxException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 49 with GFacException

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

the class UNICORESecurityContext method getDefaultConfiguration.

public DefaultClientConfiguration getDefaultConfiguration(Boolean enableMessageLogging, UserConfigurationDataModel userDataModel) throws GFacException, ApplicationSettingsException {
    X509Credential cred = null;
    try {
        boolean genCert = userDataModel.isGenerateCert();
        if (genCert) {
            String userDN = userDataModel.getUserDN();
            if (userDN == null || "".equals(userDN)) {
                log.warn("Cannot generate cert, falling back to GFAC configured MyProxy credentials");
                return getDefaultConfiguration(enableMessageLogging);
            } else {
                log.info("Generating X.509 certificate for: " + userDN);
                try {
                    String caCertPath = ServerSettings.getSetting(BESConstants.PROP_CA_CERT_PATH, "");
                    String caKeyPath = ServerSettings.getSetting(BESConstants.PROP_CA_KEY_PATH, "");
                    String caKeyPass = ServerSettings.getSetting(BESConstants.PROP_CA_KEY_PASS, "");
                    if (caCertPath.equals("") || caKeyPath.equals("")) {
                        throw new Exception("CA certificate or key file path missing in the properties file. " + "Please make sure " + BESConstants.PROP_CA_CERT_PATH + " or " + BESConstants.PROP_CA_KEY_PATH + " are not empty.");
                    }
                    if ("".equals(caKeyPass)) {
                        log.warn("Caution: CA key has no password. For security reasons it is highly recommended to set a CA key password");
                    }
                    cred = generateShortLivedCredential(userDN, caCertPath, caKeyPath, caKeyPass);
                } catch (Exception e) {
                    throw new GFacException("Error occured while generating a short lived credential for user:" + userDN, e);
                }
            }
        } else {
            return getDefaultConfiguration(enableMessageLogging);
        }
        secProperties = new DefaultClientConfiguration(dcValidator, cred);
        setExtraSettings();
    } catch (Exception e) {
        throw new GFacException(e.getMessage(), e);
    }
    secProperties.getETDSettings().setExtendTrustDelegation(true);
    if (enableMessageLogging)
        secProperties.setMessageLogging(true);
    // secProperties.setDoSignMessage(true);
    secProperties.getETDSettings().setIssuerCertificateChain(secProperties.getCredential().getCertificateChain());
    return secProperties;
}
Also used : X509Credential(eu.emi.security.authn.x509.X509Credential) GFacException(org.apache.airavata.gfac.core.GFacException) DefaultClientConfiguration(eu.unicore.util.httpclient.DefaultClientConfiguration) GFacException(org.apache.airavata.gfac.core.GFacException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 50 with GFacException

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

the class X509SecurityContext method getX509Credentials.

/**
 * Gets X509Credentials. The process is as follows;
 * If credentials were queried for the first time create credentials.
 *   1. Try creating credentials using certificates stored in the credential store
 *   2. If 1 fails use user name and password to create credentials
 * @return x509credentials (from CANL security API)
 * @throws org.apache.airavata.common.exception.ApplicationSettingsException
 */
public X509Credential getX509Credentials() throws GFacException, ApplicationSettingsException {
    if (getCredentialReader() == null) {
        return getDefaultCredentials();
    }
    if (x509Credentials == null) {
        try {
            x509Credentials = getCredentialsFromStore();
        } catch (Exception e) {
            log.error("An exception occurred while retrieving credentials from the credential store. " + "Will continue with my proxy user name and password.", e);
        }
        // If store does not have credentials try to get from user name and password
        if (x509Credentials == null) {
            x509Credentials = getDefaultCredentials();
        }
        // if still null, throw an exception
        if (x509Credentials == null) {
            throw new GFacException("Unable to retrieve my proxy credentials to continue operation.");
        }
    } else {
        try {
            final long remainingTime = x509Credentials.getCertificate().getNotAfter().getTime() - new Date().getTime();
            if (remainingTime < CREDENTIAL_RENEWING_THRESH_HOLD) {
                // return renewCredentials();
                log.warn("Do not support credentials renewal");
            }
            log.info("Fall back to get new default credentials");
            try {
                x509Credentials.getCertificate().checkValidity();
            } catch (Exception e) {
                x509Credentials = getDefaultCredentials();
            }
        } catch (Exception e) {
            throw new GFacException("Unable to retrieve remaining life time from credentials.", e);
        }
    }
    return x509Credentials;
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Date(java.util.Date)

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