Search in sources :

Example 36 with GFacException

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

the class ProcessContext method getComputeResourceServerInfo.

public ServerInfo getComputeResourceServerInfo() throws GFacException {
    if (this.jobSubmissionProtocol == JobSubmissionProtocol.SSH) {
        Optional<JobSubmissionInterface> firstJobSubmissionIface = getComputeResourceDescription().getJobSubmissionInterfaces().stream().filter(iface -> iface.getJobSubmissionProtocol() == JobSubmissionProtocol.SSH).findFirst();
        if (firstJobSubmissionIface.isPresent()) {
            try {
                SSHJobSubmission sshJobSubmission = appCatalog.getComputeResource().getSSHJobSubmission(firstJobSubmissionIface.get().getJobSubmissionInterfaceId());
                String alternateHostName = sshJobSubmission.getAlternativeSSHHostName();
                String hostName = !(alternateHostName == null || alternateHostName.length() == 0) ? alternateHostName : getComputeResourceDescription().getHostName();
                if (sshJobSubmission.getSshPort() > 0) {
                    return new ServerInfo(getComputeResourceLoginUserName(), hostName, getComputeResourceCredentialToken(), sshJobSubmission.getSshPort());
                } else {
                    return new ServerInfo(getComputeResourceLoginUserName(), hostName, getComputeResourceCredentialToken());
                }
            } catch (AppCatalogException e) {
                throw new GFacException("Failed to fetch ssh job submission for interface " + firstJobSubmissionIface.get().getJobSubmissionInterfaceId(), e);
            }
        }
    }
    return new ServerInfo(getComputeResourceLoginUserName(), getComputeResourceDescription().getHostName(), getComputeResourceCredentialToken());
}
Also used : ExperimentCatalog(org.apache.airavata.registry.cpi.ExperimentCatalog) java.util(java.util) DataMovementProtocol(org.apache.airavata.model.data.movement.DataMovementProtocol) JobModel(org.apache.airavata.model.job.JobModel) LoggerFactory(org.slf4j.LoggerFactory) UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) UserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile) Publisher(org.apache.airavata.messaging.core.Publisher) TaskModel(org.apache.airavata.model.task.TaskModel) StorageResourceDescription(org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription) UserStoragePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference) Logger(org.slf4j.Logger) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GFacException(org.apache.airavata.gfac.core.GFacException) ApplicationInterfaceDescription(org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription) ProcessState(org.apache.airavata.model.status.ProcessState) ProcessStatus(org.apache.airavata.model.status.ProcessStatus) RemoteCluster(org.apache.airavata.gfac.core.cluster.RemoteCluster) SSHKeyAuthentication(org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication) StoragePreference(org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) AppCatalog(org.apache.airavata.registry.cpi.AppCatalog) CuratorFramework(org.apache.curator.framework.CuratorFramework) ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel) AiravataUtils(org.apache.airavata.common.utils.AiravataUtils) ProcessModel(org.apache.airavata.model.process.ProcessModel) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo) org.apache.airavata.model.appcatalog.computeresource(org.apache.airavata.model.appcatalog.computeresource) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GFacException(org.apache.airavata.gfac.core.GFacException) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo)

Example 37 with GFacException

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

the class GFacYamlConfigruation method parse.

private void parse(InputStream resourceAsStream) throws GFacException {
    if (resourceAsStream == null) {
        throw new GFacException("Configuration file{gfac-config.yaml} is not fund");
    }
    Yaml yaml = new Yaml();
    Object load = yaml.load(resourceAsStream);
    if (load == null) {
        throw new GFacException("Yaml configuration object null");
    }
    if (load instanceof Map) {
        Map<String, Object> loadMap = (Map<String, Object>) load;
        String identifier;
        List<Map<String, Object>> jobSubYamls = (List<Map<String, Object>>) loadMap.get(JOB_SUBMITTERS);
        JobSubmitterTaskConfig jobSubmitterTaskConfig;
        if (jobSubYamls != null) {
            for (Map<String, Object> jobSub : jobSubYamls) {
                jobSubmitterTaskConfig = new JobSubmitterTaskConfig();
                identifier = ((String) jobSub.get(SUBMISSIO_PROTOCOL));
                jobSubmitterTaskConfig.setSubmissionProtocol(JobSubmissionProtocol.valueOf(identifier));
                jobSubmitterTaskConfig.setTaskClass(((String) jobSub.get(TASK_CLASS)));
                Object propertiesObj = jobSub.get(PROPERTIES);
                List propertiesList;
                if (propertiesObj instanceof List) {
                    propertiesList = ((List) propertiesObj);
                    if (propertiesList.size() > 0) {
                        Map<String, String> props = (Map<String, String>) propertiesList.get(0);
                        jobSubmitterTaskConfig.addProperties(props);
                    }
                }
                jobSubmitters.add(jobSubmitterTaskConfig);
            }
        }
        List<Map<String, Object>> fileTransYamls = (List<Map<String, Object>>) loadMap.get(FILE_TRANSFER_TASKS);
        DataTransferTaskConfig dataTransferTaskConfig;
        if (fileTransYamls != null) {
            for (Map<String, Object> fileTransConfig : fileTransYamls) {
                dataTransferTaskConfig = new DataTransferTaskConfig();
                identifier = ((String) fileTransConfig.get(TRANSFER_PROTOCOL));
                dataTransferTaskConfig.setTransferProtocol(DataMovementProtocol.valueOf(identifier));
                dataTransferTaskConfig.setTaskClass(((String) fileTransConfig.get(TASK_CLASS)));
                Object propertiesObj = fileTransConfig.get(PROPERTIES);
                List propertiesList;
                if (propertiesObj instanceof List) {
                    propertiesList = (List) propertiesObj;
                    if (propertiesList.size() > 0) {
                        Map<String, String> props = (Map<String, String>) propertiesList.get(0);
                        dataTransferTaskConfig.addProperties(props);
                    }
                }
                fileTransferTasks.add(dataTransferTaskConfig);
            }
        }
        List<Map<String, Object>> resourcesYaml = (List<Map<String, Object>>) loadMap.get(RESOURCES);
        ResourceConfig resourceConfig;
        if (resourcesYaml != null) {
            for (Map<String, Object> resource : resourcesYaml) {
                resourceConfig = new ResourceConfig();
                identifier = resource.get(JOB_MANAGER_TYPE).toString();
                resourceConfig.setJobManagerType(ResourceJobManagerType.valueOf(identifier));
                resourceConfig.setCommandOutputParser(resource.get(COMMAND_OUTPUT_PARSER).toString());
                Object emailParser = resource.get(EMAIL_PARSER);
                if (emailParser != null) {
                    resourceConfig.setEmailParser(emailParser.toString());
                }
                List<String> emailAddressList = (List<String>) resource.get(RESOURCE_EMAIL_ADDRESS);
                resourceConfig.setResourceEmailAddresses(emailAddressList);
                resources.add(resourceConfig);
            }
        }
    }
}
Also used : Yaml(org.yaml.snakeyaml.Yaml) GFacException(org.apache.airavata.gfac.core.GFacException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 38 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, UserConfigurationData userData) throws GFacException, ApplicationSettingsException {
    X509Credential cred = null;
    try {
        boolean genCert = userData.isGenerateCert();
        if (genCert) {
            String userDN = userData.getUserDN();
            if (userDN == null && "".equals(userDN)) {
                log.warn("Cannot generate cert, falling back to container 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 GFacProviderException("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) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException) GFacException(org.apache.airavata.gfac.core.GFacException) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 39 with GFacException

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

the class UNICORESecurityContext method getDefaultConfiguration.

/**
 * Get client configuration from MyProxy credentials.
 *
 * @return an instance of the default client configuration
 * @throws GFacException
 * @throws ApplicationSettingsException
 * @throws GFacException, ApplicationSettingsException
 */
public DefaultClientConfiguration getDefaultConfiguration(Boolean enableMessageLogging) throws GFacException, ApplicationSettingsException {
    try {
        X509Credential cred = getX509Credentials();
        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.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) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 40 with GFacException

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

the class X509SecurityContext method getDefaultCredentials.

/**
 * Gets the default proxy certificate.
 * @return Default my proxy credentials.
 * @throws GFacException If an error occurred while retrieving credentials.
 * @throws org.apache.airavata.common.exception.ApplicationSettingsException
 */
public X509Credential getDefaultCredentials() throws GFacException, ApplicationSettingsException {
    MyProxyLogon logon = new MyProxyLogon();
    logon.setValidator(dcValidator);
    logon.setHost(getRequestData().getMyProxyServerUrl());
    logon.setPort(getRequestData().getMyProxyPort());
    logon.setUsername(getRequestData().getMyProxyUserName());
    logon.setPassphrase(getRequestData().getMyProxyPassword().toCharArray());
    logon.setLifetime(getRequestData().getMyProxyLifeTime());
    try {
        logon.connect();
        logon.logon();
        logon.getCredentials();
        logon.disconnect();
        PrivateKey pk = logon.getPrivateKey();
        return new KeyAndCertCredential(pk, new X509Certificate[] { logon.getCertificate() });
    } catch (Exception e) {
        throw new GFacException("An error occurred while retrieving default security credentials.", e);
    }
}
Also used : PrivateKey(java.security.PrivateKey) GFacException(org.apache.airavata.gfac.core.GFacException) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) MyProxyLogon(org.apache.airavata.gfac.bes.utils.MyProxyLogon) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) 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