Search in sources :

Example 21 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class SimpleOrchestratorImpl method createAndSaveTasks.

public String createAndSaveTasks(String gatewayId, ProcessModel processModel, boolean autoSchedule) throws OrchestratorException {
    try {
        ExperimentCatalog experimentCatalog = orchestratorContext.getRegistry().getExperimentCatalog();
        AppCatalog appCatalog = orchestratorContext.getRegistry().getAppCatalog();
        ComputationalResourceSchedulingModel resourceSchedule = processModel.getProcessResourceSchedule();
        String userGivenQueueName = resourceSchedule.getQueueName();
        int userGivenWallTime = resourceSchedule.getWallTimeLimit();
        String resourceHostId = resourceSchedule.getResourceHostId();
        if (resourceHostId == null) {
            throw new OrchestratorException("Compute Resource Id cannot be null at this point");
        }
        ComputeResourceDescription computeResource = appCatalog.getComputeResource().getComputeResource(resourceHostId);
        JobSubmissionInterface preferredJobSubmissionInterface = OrchestratorUtils.getPreferredJobSubmissionInterface(orchestratorContext, processModel, gatewayId);
        ComputeResourcePreference resourcePreference = OrchestratorUtils.getComputeResourcePreference(orchestratorContext, processModel, gatewayId);
        List<String> taskIdList = new ArrayList<>();
        if (resourcePreference.getPreferredJobSubmissionProtocol() == JobSubmissionProtocol.UNICORE) {
            // TODO - breakdown unicore all in one task to multiple tasks, then we don't need to handle UNICORE here.
            taskIdList.addAll(createAndSaveSubmissionTasks(gatewayId, preferredJobSubmissionInterface, processModel, userGivenWallTime));
        } else {
            taskIdList.addAll(createAndSaveEnvSetupTask(gatewayId, processModel, experimentCatalog));
            taskIdList.addAll(createAndSaveInputDataStagingTasks(processModel, gatewayId));
            if (autoSchedule) {
                List<BatchQueue> definedBatchQueues = computeResource.getBatchQueues();
                for (BatchQueue batchQueue : definedBatchQueues) {
                    if (batchQueue.getQueueName().equals(userGivenQueueName)) {
                        int maxRunTime = batchQueue.getMaxRunTime();
                        if (maxRunTime < userGivenWallTime) {
                            resourceSchedule.setWallTimeLimit(maxRunTime);
                            // need to create more job submissions
                            int numOfMaxWallTimeJobs = ((int) Math.floor(userGivenWallTime / maxRunTime));
                            for (int i = 1; i <= numOfMaxWallTimeJobs; i++) {
                                taskIdList.addAll(createAndSaveSubmissionTasks(gatewayId, preferredJobSubmissionInterface, processModel, maxRunTime));
                            }
                            int leftWallTime = userGivenWallTime % maxRunTime;
                            if (leftWallTime != 0) {
                                taskIdList.addAll(createAndSaveSubmissionTasks(gatewayId, preferredJobSubmissionInterface, processModel, leftWallTime));
                            }
                        } else {
                            taskIdList.addAll(createAndSaveSubmissionTasks(gatewayId, preferredJobSubmissionInterface, processModel, userGivenWallTime));
                        }
                    }
                }
            } else {
                taskIdList.addAll(createAndSaveSubmissionTasks(gatewayId, preferredJobSubmissionInterface, processModel, userGivenWallTime));
            }
            taskIdList.addAll(createAndSaveOutputDataStagingTasks(processModel, gatewayId));
        }
        // update process scheduling
        experimentCatalog.update(ExperimentCatalogModelType.PROCESS, processModel, processModel.getProcessId());
        return getTaskDag(taskIdList);
    } catch (Exception e) {
        throw new OrchestratorException("Error during creating process", e);
    }
}
Also used : ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) URISyntaxException(java.net.URISyntaxException) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) AiravataException(org.apache.airavata.common.exception.AiravataException) TaskException(org.apache.airavata.gfac.core.task.TaskException) LaunchValidationException(org.apache.airavata.model.error.LaunchValidationException) TException(org.apache.thrift.TException) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)

Example 22 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class SimpleOrchestratorImpl method createAndSaveEnvSetupTask.

private List<String> createAndSaveEnvSetupTask(String gatewayId, ProcessModel processModel, ExperimentCatalog experimentCatalog) throws RegistryException, TException, AiravataException {
    List<String> envTaskIds = new ArrayList<>();
    TaskModel envSetupTask = new TaskModel();
    envSetupTask.setTaskType(TaskTypes.ENV_SETUP);
    envSetupTask.setTaskStatuses(Arrays.asList(new TaskStatus(TaskState.CREATED)));
    envSetupTask.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
    envSetupTask.setParentProcessId(processModel.getProcessId());
    EnvironmentSetupTaskModel envSetupSubModel = new EnvironmentSetupTaskModel();
    envSetupSubModel.setProtocol(OrchestratorUtils.getSecurityProtocol(orchestratorContext, processModel, gatewayId));
    ComputeResourcePreference computeResourcePreference = OrchestratorUtils.getComputeResourcePreference(orchestratorContext, processModel, gatewayId);
    String scratchLocation = OrchestratorUtils.getScratchLocation(orchestratorContext, processModel, gatewayId);
    String workingDir = scratchLocation + File.separator + processModel.getProcessId();
    envSetupSubModel.setLocation(workingDir);
    byte[] envSetupSub = ThriftUtils.serializeThriftObject(envSetupSubModel);
    envSetupTask.setSubTaskModel(envSetupSub);
    String envSetupTaskId = (String) experimentCatalog.add(ExpCatChildDataType.TASK, envSetupTask, processModel.getProcessId());
    envSetupTask.setTaskId(envSetupTaskId);
    envTaskIds.add(envSetupTaskId);
    return envTaskIds;
}
Also used : ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) TaskStatus(org.apache.airavata.model.status.TaskStatus)

Example 23 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class ClusterStatusMonitorJob method execute.

@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    try {
        String superTenantGatewayId = ServerSettings.getSuperTenantGatewayId();
        RegistryService.Client registryClient = getRegistryClient();
        List<ComputeResourceProfile> computeResourceProfiles = new ArrayList<>();
        List<ComputeResourcePreference> computeResourcePreferences = null;
        try {
            computeResourcePreferences = registryClient.getAllGatewayComputeResourcePreferences(superTenantGatewayId);
        } catch (Exception ex) {
            logger.warn("Could not find super tenant compute resources preferences for cluster status monitoring...");
        }
        if (computeResourcePreferences != null && computeResourcePreferences.size() > 0) {
            computeResourcePreferences.stream().forEach(p -> {
                try {
                    String computeResourceId = p.getComputeResourceId();
                    String credentialStoreToken = p.getResourceSpecificCredentialStoreToken();
                    String loginUserName = p.getLoginUserName();
                    String hostName = null;
                    if (credentialStoreToken == null || credentialStoreToken.equals("")) {
                        credentialStoreToken = registryClient.getGatewayResourceProfile(superTenantGatewayId).getCredentialStoreToken();
                    }
                    int port = -1;
                    ArrayList queueNames = new ArrayList<>();
                    ComputeResourceDescription computeResourceDescription = registryClient.getComputeResource(computeResourceId);
                    hostName = computeResourceDescription.getHostName();
                    // FIXME This should come from compute resource description
                    port = 22;
                    computeResourceDescription.getBatchQueues().stream().forEach(q -> {
                        queueNames.add(q.getQueueName());
                    });
                    List<JobSubmissionInterface> jobSubmissionInterfaces = computeResourceDescription.getJobSubmissionInterfaces();
                    if (jobSubmissionInterfaces != null && jobSubmissionInterfaces.size() > 0) {
                        if (jobSubmissionInterfaces.get(0).getJobSubmissionProtocol().equals(JobSubmissionProtocol.SSH)) {
                            String resourceManagerType = registryClient.getSSHJobSubmission(jobSubmissionInterfaces.get(0).getJobSubmissionInterfaceId()).getResourceJobManager().getResourceJobManagerType().name();
                            ComputeResourceProfile computeResourceProfile = new ComputeResourceProfile(hostName, loginUserName, port, credentialStoreToken, queueNames, resourceManagerType);
                            computeResourceProfiles.add(computeResourceProfile);
                        }
                    }
                } catch (TException e) {
                    logger.error(e.getMessage());
                }
            });
        }
        ArrayList<QueueStatusModel> queueStatuses = new ArrayList<>();
        for (ComputeResourceProfile computeResourceProfile : computeResourceProfiles) {
            String userName = computeResourceProfile.getUserName();
            String hostName = computeResourceProfile.getHostName();
            int port = computeResourceProfile.getPort();
            try {
                JSch jsch = new JSch();
                CredentialStoreService.Client credentialClient = getCredentialStoreClient();
                SSHCredential sshCredential = credentialClient.getSSHCredential(computeResourceProfile.getCredentialStoreToken(), superTenantGatewayId);
                jsch.addIdentity(hostName, sshCredential.getPrivateKey().getBytes(), sshCredential.getPublicKey().getBytes(), sshCredential.getPassphrase().getBytes());
                Session session = jsch.getSession(userName, hostName, port);
                java.util.Properties config = new java.util.Properties();
                config.put("StrictHostKeyChecking", "no");
                session.setConfig(config);
                logger.debug("Connected to " + hostName);
                session.connect();
                for (String queue : computeResourceProfile.getQueueNames()) {
                    String command = "";
                    if (computeResourceProfile.getResourceManagerType().equals("SLURM"))
                        command = "sinfo -s -p " + queue + " -o \"%a %F\" | tail -1";
                    else if (computeResourceProfile.getResourceManagerType().equals("PBS"))
                        command = "qstat -Q " + queue + "| tail -1";
                    if (command.equals("")) {
                        logger.warn("No matching resource manager type found for " + computeResourceProfile.getResourceManagerType());
                        continue;
                    }
                    Channel channel = session.openChannel("exec");
                    ((ChannelExec) channel).setCommand(command);
                    channel.setInputStream(null);
                    ((ChannelExec) channel).setErrStream(System.err);
                    InputStream in = channel.getInputStream();
                    channel.connect();
                    byte[] tmp = new byte[1024];
                    String result = "";
                    while (true) {
                        while (in.available() > 0) {
                            int i = in.read(tmp, 0, 1024);
                            if (i < 0)
                                break;
                            result += new String(tmp, 0, i);
                        }
                        if (channel.isClosed()) {
                            if (in.available() > 0)
                                continue;
                            logger.debug(hostName + " " + queue + " " + "exit-status: " + channel.getExitStatus());
                            break;
                        }
                        try {
                            Thread.sleep(1000);
                        } catch (Exception ee) {
                        }
                    }
                    channel.disconnect();
                    if (result != null && result.length() > 0) {
                        QueueStatusModel queueStatus = null;
                        if (computeResourceProfile.getResourceManagerType().equals("SLURM")) {
                            String[] sparts = result.split(" ");
                            boolean isUp = sparts[0].equalsIgnoreCase("up");
                            String knts = sparts[1];
                            sparts = knts.split("/");
                            int running = Integer.parseInt(sparts[0].trim());
                            int queued = Integer.parseInt(sparts[1].trim());
                            queueStatus = new QueueStatusModel(hostName, queue, isUp, running, queued, System.currentTimeMillis());
                        } else if (computeResourceProfile.getResourceManagerType().equals("PBS")) {
                            result = result.replaceAll("\\s+", " ");
                            String[] sparts = result.split(" ");
                            boolean isUp = sparts[3].equalsIgnoreCase("yes");
                            int running = Integer.parseInt(sparts[6].trim());
                            int queued = Integer.parseInt(sparts[5].trim());
                            queueStatus = new QueueStatusModel(hostName, queue, isUp, running, queued, System.currentTimeMillis());
                        }
                        if (queueStatus != null)
                            queueStatuses.add(queueStatus);
                    }
                }
                session.disconnect();
            } catch (Exception ex) {
                logger.error("Failed to get cluster status from " + computeResourceProfile.getHostName());
                logger.error(ex.getMessage(), ex);
            }
        }
        if (queueStatuses != null && queueStatuses.size() > 0) {
            registryClient.registerQueueStatuses(queueStatuses);
        }
    } catch (Exception e) {
        throw new JobExecutionException(e);
    }
}
Also used : TException(org.apache.thrift.TException) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) JobSubmissionInterface(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface) ArrayList(java.util.ArrayList) JSch(com.jcraft.jsch.JSch) JobExecutionException(org.quartz.JobExecutionException) QueueStatusModel(org.apache.airavata.model.status.QueueStatusModel) RegistryService(org.apache.airavata.registry.api.RegistryService) SSHCredential(org.apache.airavata.model.credential.store.SSHCredential) ComputeResourceDescription(org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription) InputStream(java.io.InputStream) Channel(com.jcraft.jsch.Channel) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) JobExecutionException(org.quartz.JobExecutionException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ChannelExec(com.jcraft.jsch.ChannelExec) CredentialStoreService(org.apache.airavata.credential.store.cpi.CredentialStoreService) Session(com.jcraft.jsch.Session)

Example 24 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class GatewayProfileTest method gatewayProfileTest.

@Test
public void gatewayProfileTest() throws Exception {
    GwyResourceProfile gatewayProfile = appcatalog.getGatewayProfile();
    GatewayResourceProfile gf = new GatewayResourceProfile();
    ComputeResource computeRs = appcatalog.getComputeResource();
    ComputeResourceDescription cm1 = new ComputeResourceDescription();
    cm1.setHostName("localhost");
    cm1.setResourceDescription("test compute host");
    String hostId1 = computeRs.addComputeResource(cm1);
    ComputeResourceDescription cm2 = new ComputeResourceDescription();
    cm2.setHostName("localhost");
    cm2.setResourceDescription("test compute host");
    String hostId2 = computeRs.addComputeResource(cm2);
    ComputeResourcePreference preference1 = new ComputeResourcePreference();
    preference1.setComputeResourceId(hostId1);
    preference1.setOverridebyAiravata(true);
    preference1.setPreferredJobSubmissionProtocol(JobSubmissionProtocol.SSH);
    preference1.setPreferredDataMovementProtocol(DataMovementProtocol.SCP);
    preference1.setPreferredBatchQueue("queue1");
    preference1.setScratchLocation("/tmp");
    preference1.setAllocationProjectNumber("project1");
    ComputeResourcePreference preference2 = new ComputeResourcePreference();
    preference2.setComputeResourceId(hostId2);
    preference2.setOverridebyAiravata(true);
    preference2.setPreferredJobSubmissionProtocol(JobSubmissionProtocol.LOCAL);
    preference2.setPreferredDataMovementProtocol(DataMovementProtocol.GridFTP);
    preference2.setPreferredBatchQueue("queue2");
    preference2.setScratchLocation("/tmp");
    preference2.setAllocationProjectNumber("project2");
    List<ComputeResourcePreference> list = new ArrayList<ComputeResourcePreference>();
    list.add(preference1);
    list.add(preference2);
    gf.setComputeResourcePreferences(list);
    gf.setGatewayID("testGateway");
    String gwId = gatewayProfile.addGatewayResourceProfile(gf);
    GatewayResourceProfile retrievedProfile = null;
    if (gatewayProfile.isGatewayResourceProfileExists(gwId)) {
        retrievedProfile = gatewayProfile.getGatewayProfile(gwId);
        System.out.println("************ gateway id ************** :" + retrievedProfile.getGatewayID());
    }
    List<ComputeResourcePreference> preferences = gatewayProfile.getAllComputeResourcePreferences(gwId);
    System.out.println("compute preferences size : " + preferences.size());
    if (preferences != null && !preferences.isEmpty()) {
        for (ComputeResourcePreference cm : preferences) {
            System.out.println("******** host id ********* : " + cm.getComputeResourceId());
            System.out.println(cm.getPreferredBatchQueue());
            System.out.println(cm.getPreferredDataMovementProtocol());
            System.out.println(cm.getPreferredJobSubmissionProtocol());
        }
    }
    assertTrue("App interface saved successfully", retrievedProfile != null);
}
Also used : ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) GwyResourceProfile(org.apache.airavata.registry.cpi.GwyResourceProfile) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) ComputeResourceDescription(org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription) ArrayList(java.util.ArrayList) ComputeResource(org.apache.airavata.registry.cpi.ComputeResource) Test(org.junit.Test)

Example 25 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class SampleEchoExperiment method registerGatewayProfile.

private void registerGatewayProfile() throws TException {
    GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
    ComputeResourcePreference localhostResourcePreference = RegisterSampleApplicationsUtils.createComputeResourcePreference(localhostId, gatewayId, false, null, null, null, "/tmp");
    gatewayResourceProfile.setGatewayID(gatewayId);
    gatewayResourceProfile.addToComputeResourcePreferences(localhostResourcePreference);
    airavataClient.registerGatewayResourceProfile(new AuthzToken(""), gatewayResourceProfile);
}
Also used : ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) AuthzToken(org.apache.airavata.model.security.AuthzToken)

Aggregations

ComputeResourcePreference (org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference)30 GatewayResourceProfile (org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile)10 UserComputeResourcePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference)10 TException (org.apache.thrift.TException)10 AiravataException (org.apache.airavata.common.exception.AiravataException)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)5 ComputeResourceDescription (org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription)5 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)5 StoragePreference (org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference)4 RegistryService (org.apache.airavata.registry.api.RegistryService)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)3 JobSubmissionInterface (org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface)3 AuthzToken (org.apache.airavata.model.security.AuthzToken)3 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)3 ApplicationDeploymentDescription (org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription)2 ApplicationInterfaceDescription (org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription)2 LaunchValidationException (org.apache.airavata.model.error.LaunchValidationException)2 ComputationalResourceSchedulingModel (org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)2