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());
}
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);
}
}
}
}
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;
}
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;
}
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);
}
}
Aggregations