Search in sources :

Example 16 with AiravataSystemException

use of org.apache.airavata.model.error.AiravataSystemException in project airavata by apache.

the class GatewayRegister method registerSSHKeys.

public void registerSSHKeys() throws Exception {
    try {
        // write tokens to file
        String tokenWriteLocation = properties.getTokenFileLoc();
        String fileName = tokenWriteLocation + File.separator + TestFrameworkConstants.CredentialStoreConstants.TOKEN_FILE_NAME;
        PrintWriter tokenWriter = new PrintWriter(fileName, "UTF-8");
        // credential store related functions are not in the current api, so need to call credential store directly
        String jdbcURL = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_JBDC_URL, PropertyFileType.AIRAVATA_SERVER);
        String jdbcDriver = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_JBDC_DRIVER, PropertyFileType.AIRAVATA_SERVER);
        String userName = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_DB_USERNAME, PropertyFileType.AIRAVATA_SERVER);
        String password = propertyReader.readProperty(TestFrameworkConstants.AiravataClientConstants.CS_DB_PWD, PropertyFileType.AIRAVATA_SERVER);
        String privateKeyPath = properties.getSshPrivateKeyLoc();
        String pubKeyPath = properties.getSshPubKeyLoc();
        String keyPassword = properties.getSshPassword();
        DBUtil dbUtil = new DBUtil(jdbcURL, userName, password, jdbcDriver);
        SSHCredentialWriter writer = new SSHCredentialWriter(dbUtil);
        Gateway gateway = airavata.getGateway(authzToken, properties.getGname());
        SSHCredential sshCredential = new SSHCredential();
        sshCredential.setGateway(gateway.getGatewayId());
        String token = TokenGenerator.generateToken(gateway.getGatewayId(), null);
        sshCredential.setToken(token);
        sshCredential.setPortalUserName(testUser);
        FileInputStream privateKeyStream = new FileInputStream(privateKeyPath);
        File filePri = new File(privateKeyPath);
        byte[] bFilePri = new byte[(int) filePri.length()];
        privateKeyStream.read(bFilePri);
        FileInputStream pubKeyStream = new FileInputStream(pubKeyPath);
        File filePub = new File(pubKeyPath);
        byte[] bFilePub = new byte[(int) filePub.length()];
        pubKeyStream.read(bFilePub);
        privateKeyStream.close();
        pubKeyStream.close();
        sshCredential.setPrivateKey(bFilePri);
        sshCredential.setPublicKey(bFilePub);
        sshCredential.setPassphrase(keyPassword);
        writer.writeCredentials(sshCredential);
        tokenMap.put(gateway.getGatewayId(), token);
        tokenWriter.println(gateway.getGatewayId() + ":" + token);
        tokenWriter.close();
    } catch (ClassNotFoundException e) {
        logger.error("Unable to find mysql driver", e);
        throw new Exception("Unable to find mysql driver", e);
    } catch (InstantiationException e) {
        logger.error("Error while saving SSH credentials", e);
        throw new Exception("Error while saving SSH credentials", e);
    } catch (IllegalAccessException e) {
        logger.error("Error while saving SSH credentials", e);
        throw new Exception("Error while saving SSH credentials", e);
    } catch (ApplicationSettingsException e) {
        logger.error("Unable to read airavata-client properties", e);
        throw new Exception("Unable to read airavata-client properties", e);
    } catch (AiravataSystemException e) {
        logger.error("Error occured while connecting with airavata client", e);
        throw new Exception("Error occured while connecting with airavata client", e);
    } catch (InvalidRequestException e) {
        logger.error("Error occured while connecting with airavata client", e);
        throw new Exception("Error occured while connecting with airavata client", e);
    } catch (AiravataClientException e) {
        logger.error("Error occured while connecting with airavata client", e);
        throw new Exception("Error occured while connecting with airavata client", e);
    } catch (TException e) {
        logger.error("Error occured while connecting with airavata client", e);
        throw new Exception("Error occured while connecting with airavata client", e);
    } catch (FileNotFoundException e) {
        logger.error("Could not find keys specified in the path", e);
        throw new Exception("Could not find keys specified in the path", e);
    } catch (CredentialStoreException e) {
        logger.error("Error while saving SSH credentials", e);
        throw new Exception("Error while saving SSH credentials", e);
    } catch (IOException e) {
        logger.error("Error while saving SSH credentials", e);
        throw new Exception("Error while saving SSH credentials", e);
    }
}
Also used : TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SSHCredentialWriter(org.apache.airavata.credential.store.store.impl.SSHCredentialWriter) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) TException(org.apache.thrift.TException) AiravataClientException(org.apache.airavata.model.error.AiravataClientException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AiravataSystemException(org.apache.airavata.model.error.AiravataSystemException) DBUtil(org.apache.airavata.common.utils.DBUtil) AiravataSystemException(org.apache.airavata.model.error.AiravataSystemException) Gateway(org.apache.airavata.model.workspace.Gateway) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) AiravataClientException(org.apache.airavata.model.error.AiravataClientException)

Aggregations

AiravataSystemException (org.apache.airavata.model.error.AiravataSystemException)16 AiravataClientException (org.apache.airavata.model.error.AiravataClientException)15 InvalidRequestException (org.apache.airavata.model.error.InvalidRequestException)15 TException (org.apache.thrift.TException)15 ArrayList (java.util.ArrayList)6 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)6 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)6 ExperimentModel (org.apache.airavata.model.experiment.ExperimentModel)6 UserConfigurationDataModel (org.apache.airavata.model.experiment.UserConfigurationDataModel)6 ComputationalResourceSchedulingModel (org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)6 AuthzToken (org.apache.airavata.model.security.AuthzToken)6 Project (org.apache.airavata.model.workspace.Project)5 XBayaLabel (org.apache.airavata.xbaya.ui.widgets.XBayaLabel)4 XBayaTextField (org.apache.airavata.xbaya.ui.widgets.XBayaTextField)4 JLabel (javax.swing.JLabel)3 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)3 ActionEvent (java.awt.event.ActionEvent)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2