Search in sources :

Example 11 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class GFacUtils method createGroovyMap.

public static GroovyMap createGroovyMap(ProcessContext processContext, TaskContext taskContext) throws GFacException, AppCatalogException, ApplicationSettingsException {
    GroovyMap groovyMap = new GroovyMap();
    ProcessModel processModel = processContext.getProcessModel();
    ResourceJobManager resourceJobManager = getResourceJobManager(processContext);
    // set email options and addresses
    setMailAddresses(processContext, groovyMap);
    groovyMap.add(Script.INPUT_DIR, processContext.getInputDir());
    groovyMap.add(Script.OUTPUT_DIR, processContext.getOutputDir());
    groovyMap.add(Script.EXECUTABLE_PATH, processContext.getApplicationDeploymentDescription().getExecutablePath());
    groovyMap.add(Script.STANDARD_OUT_FILE, processContext.getStdoutLocation());
    groovyMap.add(Script.STANDARD_ERROR_FILE, processContext.getStderrLocation());
    groovyMap.add(Script.SCRATCH_LOCATION, processContext.getScratchLocation());
    groovyMap.add(Script.GATEWAY_ID, processContext.getGatewayId());
    groovyMap.add(Script.GATEWAY_USER_NAME, processContext.getProcessModel().getUserName());
    groovyMap.add(Script.APPLICATION_NAME, processContext.getApplicationInterfaceDescription().getApplicationName());
    groovyMap.add(Script.QUEUE_SPECIFIC_MACROS, processContext.getQueueSpecificMacros());
    groovyMap.add(Script.ACCOUNT_STRING, processContext.getAllocationProjectNumber());
    groovyMap.add(Script.RESERVATION, processContext.getReservation());
    // To make job name alpha numeric
    groovyMap.add(Script.JOB_NAME, "A" + String.valueOf(generateJobName()));
    groovyMap.add(Script.WORKING_DIR, processContext.getWorkingDir());
    List<String> inputValues = getProcessInputValues(processModel.getProcessInputs());
    inputValues.addAll(getProcessOutputValues(processModel.getProcessOutputs()));
    groovyMap.add(Script.INPUTS, inputValues);
    groovyMap.add(Script.USER_NAME, processContext.getJobSubmissionRemoteCluster().getServerInfo().getUserName());
    groovyMap.add(Script.SHELL_NAME, "/bin/bash");
    // get walltime
    if (taskContext != null) {
        try {
            JobSubmissionTaskModel jobSubmissionTaskModel = ((JobSubmissionTaskModel) taskContext.getSubTaskModel());
            if (jobSubmissionTaskModel.getWallTime() > 0) {
                groovyMap.add(Script.MAX_WALL_TIME, GFacUtils.maxWallTimeCalculator(jobSubmissionTaskModel.getWallTime()));
                if (resourceJobManager != null) {
                    if (resourceJobManager.getResourceJobManagerType().equals(ResourceJobManagerType.LSF)) {
                        groovyMap.add(Script.MAX_WALL_TIME, GFacUtils.maxWallTimeCalculatorForLSF(jobSubmissionTaskModel.getWallTime()));
                    }
                }
            }
        } catch (TException e) {
            log.error("Error while getting job submission sub task model", e);
        }
    }
    // NOTE: Give precedence to data comes with experiment
    // qos per queue
    String qoS = getQoS(processContext.getQualityOfService(), processContext.getQueueName());
    if (qoS != null) {
        groovyMap.add(Script.QUALITY_OF_SERVICE, qoS);
    }
    ComputationalResourceSchedulingModel scheduling = processModel.getProcessResourceSchedule();
    if (scheduling != null) {
        int totalNodeCount = scheduling.getNodeCount();
        int totalCPUCount = scheduling.getTotalCPUCount();
        if (isValid(scheduling.getQueueName())) {
            groovyMap.add(Script.QUEUE_NAME, scheduling.getQueueName());
        }
        if (totalNodeCount > 0) {
            groovyMap.add(Script.NODES, totalNodeCount);
        }
        if (totalCPUCount > 0) {
            int ppn = totalCPUCount / totalNodeCount;
            groovyMap.add(Script.PROCESS_PER_NODE, ppn);
            groovyMap.add(Script.CPU_COUNT, totalCPUCount);
        }
        // if so we ignore scheduling configuration.
        if (scheduling.getWallTimeLimit() > 0 && groovyMap.get(Script.MAX_WALL_TIME) == null) {
            groovyMap.add(Script.MAX_WALL_TIME, GFacUtils.maxWallTimeCalculator(scheduling.getWallTimeLimit()));
            if (resourceJobManager != null) {
                if (resourceJobManager.getResourceJobManagerType().equals(ResourceJobManagerType.LSF)) {
                    groovyMap.add(Script.MAX_WALL_TIME, GFacUtils.maxWallTimeCalculatorForLSF(scheduling.getWallTimeLimit()));
                }
            }
        }
        if (scheduling.getTotalPhysicalMemory() > 0) {
            groovyMap.add(Script.USED_MEM, scheduling.getTotalPhysicalMemory());
        }
        if (isValid(scheduling.getOverrideLoginUserName())) {
            groovyMap.add(Script.USER_NAME, scheduling.getOverrideLoginUserName());
        }
        if (isValid(scheduling.getOverrideAllocationProjectNumber())) {
            groovyMap.add(Script.ACCOUNT_STRING, scheduling.getOverrideAllocationProjectNumber());
        }
        if (isValid(scheduling.getStaticWorkingDir())) {
            groovyMap.add(Script.WORKING_DIR, scheduling.getStaticWorkingDir());
        }
    } else {
        log.error("Task scheduling cannot be null at this point..");
    }
    ApplicationDeploymentDescription appDepDescription = processContext.getApplicationDeploymentDescription();
    List<CommandObject> moduleCmds = appDepDescription.getModuleLoadCmds();
    if (moduleCmds != null) {
        List<String> modulesCmdCollect = moduleCmds.stream().sorted((e1, e2) -> e1.getCommandOrder() - e2.getCommandOrder()).map(map -> map.getCommand()).collect(Collectors.toList());
        groovyMap.add(Script.MODULE_COMMANDS, modulesCmdCollect);
    }
    List<CommandObject> preJobCommands = appDepDescription.getPreJobCommands();
    if (preJobCommands != null) {
        List<String> preJobCmdCollect = preJobCommands.stream().sorted((e1, e2) -> e1.getCommandOrder() - e2.getCommandOrder()).map(map -> parseCommands(map.getCommand(), groovyMap)).collect(Collectors.toList());
        groovyMap.add(Script.PRE_JOB_COMMANDS, preJobCmdCollect);
    }
    List<CommandObject> postJobCommands = appDepDescription.getPostJobCommands();
    if (postJobCommands != null) {
        List<String> postJobCmdCollect = postJobCommands.stream().sorted((e1, e2) -> e1.getCommandOrder() - e2.getCommandOrder()).map(map -> parseCommands(map.getCommand(), groovyMap)).collect(Collectors.toList());
        groovyMap.add(Script.POST_JOB_COMMANDS, postJobCmdCollect);
    }
    ApplicationParallelismType parallelism = appDepDescription.getParallelism();
    if (parallelism != null) {
        if (parallelism != ApplicationParallelismType.SERIAL) {
            Map<ApplicationParallelismType, String> parallelismPrefix = processContext.getResourceJobManager().getParallelismPrefix();
            if (parallelismPrefix != null) {
                String parallelismCommand = parallelismPrefix.get(parallelism);
                if (parallelismCommand != null) {
                    groovyMap.add(Script.JOB_SUBMITTER_COMMAND, parallelismCommand);
                } else {
                    throw new GFacException("Parallelism prefix is not defined for given parallelism type " + parallelism + ".. Please define the parallelism prefix at App Catalog");
                }
            }
        }
    }
    return groovyMap;
}
Also used : TException(org.apache.thrift.TException) CreateMode(org.apache.zookeeper.CreateMode) TemplateEngine(groovy.text.TemplateEngine) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) TaskContext(org.apache.airavata.gfac.core.context.TaskContext) Stat(org.apache.zookeeper.data.Stat) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) SecureRandom(java.security.SecureRandom) ZKPaths(org.apache.curator.utils.ZKPaths) Matcher(java.util.regex.Matcher) Document(org.w3c.dom.Document) CredentialReaderImpl(org.apache.airavata.credential.store.store.impl.CredentialReaderImpl) org.apache.airavata.model.data.replica(org.apache.airavata.model.data.replica) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) DataType(org.apache.airavata.model.application.io.DataType) org.apache.airavata.common.utils(org.apache.airavata.common.utils) JobSubmissionTaskModel(org.apache.airavata.model.task.JobSubmissionTaskModel) Collectors(java.util.stream.Collectors) CuratorFramework(org.apache.curator.framework.CuratorFramework) ErrorModel(org.apache.airavata.model.commons.ErrorModel) GStringTemplateEngine(groovy.text.GStringTemplateEngine) Pattern(java.util.regex.Pattern) org.apache.airavata.model.appcatalog.computeresource(org.apache.airavata.model.appcatalog.computeresource) java.util(java.util) JobModel(org.apache.airavata.model.job.JobModel) ACL(org.apache.zookeeper.data.ACL) Writable(groovy.lang.Writable) javax.xml.xpath(javax.xml.xpath) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) Node(org.w3c.dom.Node) MessageContext(org.apache.airavata.messaging.core.MessageContext) RegistryFactory(org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) Constants(org.apache.airavata.registry.cpi.utils.Constants) TException(org.apache.thrift.TException) FileUtils(org.apache.commons.io.FileUtils) org.apache.airavata.model.status(org.apache.airavata.model.status) ApplicationParallelismType(org.apache.airavata.model.parallelism.ApplicationParallelismType) org.apache.airavata.registry.cpi(org.apache.airavata.registry.cpi) UnknownHostException(java.net.UnknownHostException) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) Element(org.w3c.dom.Element) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) ZooDefs(org.apache.zookeeper.ZooDefs) java.io(java.io) ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel) org.apache.airavata.model.messaging.event(org.apache.airavata.model.messaging.event) ProcessModel(org.apache.airavata.model.process.ProcessModel) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) CommandObject(org.apache.airavata.model.appcatalog.appdeployment.CommandObject) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) ProcessModel(org.apache.airavata.model.process.ProcessModel) ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) ApplicationParallelismType(org.apache.airavata.model.parallelism.ApplicationParallelismType) CommandObject(org.apache.airavata.model.appcatalog.appdeployment.CommandObject) JobSubmissionTaskModel(org.apache.airavata.model.task.JobSubmissionTaskModel) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)

Example 12 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class TestSSLClient method invoke.

private void invoke() {
    // TTransport transport;
    try {
        // TSSLTransportFactory.TSSLTransportParameters params =
        // new TSSLTransportFactory.TSSLTransportParameters();
        // String keystorePath = ServerSettings.getCredentialStoreThriftServerKeyStorePath();
        // String keystorePWD = ServerSettings.getCredentialStoreThriftServerKeyStorePassword();
        // params.setTrustStore(keystorePath, keystorePWD);
        final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort());
        final String serverHost = ServerSettings.getCredentialStoreServerHost();
        TTransport transport = new TSocket(serverHost, serverPort);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        // transport = TSSLTransportFactory.getClientSocket(serverHost, serverPort, 10000, params);
        // TProtocol protocol = new TBinaryProtocol(transport);
        CredentialStoreService.Client client = new CredentialStoreService.Client(protocol);
        testSSHCredential(client);
        testCertificateCredential(client);
        transport.close();
    } catch (TTransportException e) {
        e.printStackTrace();
    } catch (ApplicationSettingsException e) {
        e.printStackTrace();
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) CredentialStoreService(org.apache.airavata.credential.store.cpi.CredentialStoreService) TSocket(org.apache.thrift.transport.TSocket)

Example 13 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class NotifierBootstrap method run.

@Override
public void run() {
    if (!enabled)
        return;
    // retrieve OA4MP credentials
    try {
        CredentialReader credentialReader = new CredentialReaderImpl(this.dbUtil);
        List<Credential> credentials = credentialReader.getAllCredentials();
        for (Credential credential : credentials) {
            if (credential instanceof CertificateCredential) {
                CertificateCredential certificateCredential = (CertificateCredential) credential;
                Date date = Utility.convertStringToDate(certificateCredential.getNotAfter());
                // gap is 1 days
                date.setDate(date.getDate() + 1);
                Date currentDate = new Date();
                if (currentDate.after(date)) {
                    // Send an email
                    CommunityUser communityUser = certificateCredential.getCommunityUser();
                    String body = String.format(MESSAGE, communityUser.getUserName(), certificateCredential.getNotAfter());
                    String subject = String.format(SUBJECT, communityUser.getUserName());
                    NotificationMessage notificationMessage = new EmailNotificationMessage(subject, communityUser.getUserEmail(), body);
                    this.credentialStoreNotifier.notifyMessage(notificationMessage);
                }
            }
        }
    } catch (ApplicationSettingsException e) {
        log.error("Error configuring email senders.", e);
    } catch (CredentialStoreException e) {
        log.error("Error sending emails about credential expiring.", e);
    } catch (ParseException e) {
        log.error("Error parsing date time when sending emails", e);
    }
}
Also used : EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) CredentialReaderImpl(org.apache.airavata.credential.store.store.impl.CredentialReaderImpl) EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ParseException(java.text.ParseException)

Example 14 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class CredentialStoreInitUtil method initializeDB.

public static void initializeDB() {
    // System.setProperty("appcatalog.initialize.state", "0");
    try {
        jdbcDriver = ServerSettings.getCredentialStoreDBDriver();
        jdbcURl = ServerSettings.getCredentialStoreDBURL();
        jdbcUser = ServerSettings.getCredentialStoreDBUser();
        jdbcPassword = ServerSettings.getCredentialStoreDBPassword();
        jdbcURl = jdbcURl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
    } catch (ApplicationSettingsException e) {
        logger.error("Unable to read airavata server properties", e.getMessage());
    }
    if (getDBType(jdbcURl).equals("derby") && isDerbyStartEnabled()) {
        startDerbyInServerMode();
    }
    db = new JdbcStorage(10, 50, jdbcURl, jdbcDriver, true);
    Connection conn = null;
    try {
        conn = db.connect();
        if (!DatabaseCreator.isDatabaseStructureCreated(CREDENTIALS, conn)) {
            DatabaseCreator.createRegistryDatabase("database_scripts/credstore", conn);
            logger.info("New Database created for Credential Store !!! ");
        } else {
            logger.info("Database already created for Credential Store !!!");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException("Database failure", e);
    } finally {
        db.closeConnection(conn);
        try {
            if (conn != null) {
                if (!conn.getAutoCommit()) {
                    conn.commit();
                }
                conn.close();
            }
        } catch (SQLException e) {
            logger.error("Error while closing database connection...", e.getMessage(), e);
        }
    }
// System.setProperty("appcatalog.initialize.state", "1");
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SQLException(java.sql.SQLException) IOException(java.io.IOException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 15 with ApplicationSettingsException

use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.

the class RegistryServerHandler method getLatestQueueStatuses.

/**
 * * Get queue statuses of all compute resources
 * *
 */
@Override
public List<QueueStatusModel> getLatestQueueStatuses() throws RegistryServiceException, TException {
    try {
        experimentCatalog = RegistryFactory.getExperimentCatalog(ServerSettings.getDefaultUserGateway());
        List<Object> temp = experimentCatalog.get(ExperimentCatalogModelType.QUEUE_STATUS, null, null, -1, 0, null, null);
        List<QueueStatusModel> queueStatusModels = new ArrayList<>();
        temp.stream().forEach(t -> {
            queueStatusModels.add((QueueStatusModel) t);
        });
        return queueStatusModels;
    } catch (RegistryException | ApplicationSettingsException e) {
        logger.error("Error while reading queue status models....", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while reading queue status models.... : " + e.getMessage());
        throw exception;
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) QueueStatusModel(org.apache.airavata.model.status.QueueStatusModel) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException)

Aggregations

ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)263 EntityManager (javax.persistence.EntityManager)193 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)172 Query (javax.persistence.Query)147 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)129 HashMap (java.util.HashMap)71 Map (java.util.Map)69 ArrayList (java.util.ArrayList)47 WorkflowCatalogException (org.apache.airavata.registry.cpi.WorkflowCatalogException)26 IOException (java.io.IOException)23 IamAdminServicesException (org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException)20 TException (org.apache.thrift.TException)19 WorkflowCatalogQueryGenerator (org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator)18 GFacException (org.apache.airavata.gfac.core.GFacException)11 PasswordCredential (org.apache.airavata.model.credential.store.PasswordCredential)11 Keycloak (org.keycloak.admin.client.Keycloak)11 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)7 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)7 File (java.io.File)6 Connection (java.sql.Connection)6