Search in sources :

Example 6 with JobSubmissionInterface

use of org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface in project airavata by apache.

the class OrchestratorUtils method getSecurityProtocol.

public static SecurityProtocol getSecurityProtocol(OrchestratorContext context, ProcessModel processModel, String gatewayId) throws RegistryException {
    try {
        JobSubmissionProtocol submissionProtocol = getPreferredJobSubmissionProtocol(context, processModel, gatewayId);
        JobSubmissionInterface jobSubmissionInterface = getPreferredJobSubmissionInterface(context, processModel, gatewayId);
        if (submissionProtocol == JobSubmissionProtocol.SSH) {
            SSHJobSubmission sshJobSubmission = getSSHJobSubmission(context, jobSubmissionInterface.getJobSubmissionInterfaceId());
            if (sshJobSubmission != null) {
                return sshJobSubmission.getSecurityProtocol();
            }
        } else if (submissionProtocol == JobSubmissionProtocol.LOCAL) {
            LOCALSubmission localJobSubmission = getLocalJobSubmission(context, jobSubmissionInterface.getJobSubmissionInterfaceId());
            if (localJobSubmission != null) {
                return localJobSubmission.getSecurityProtocol();
            }
        } else if (submissionProtocol == JobSubmissionProtocol.SSH_FORK) {
            SSHJobSubmission sshJobSubmission = getSSHJobSubmission(context, jobSubmissionInterface.getJobSubmissionInterfaceId());
            if (sshJobSubmission != null) {
                return sshJobSubmission.getSecurityProtocol();
            }
        } else if (submissionProtocol == JobSubmissionProtocol.CLOUD) {
            CloudJobSubmission cloudJobSubmission = getCloudJobSubmission(context, jobSubmissionInterface.getJobSubmissionInterfaceId());
            if (cloudJobSubmission != null) {
                return cloudJobSubmission.getSecurityProtocol();
            }
        }
    } catch (RegistryException e) {
        logger.error("Error occurred while retrieving security protocol", e);
    }
    return null;
}
Also used : JobSubmissionInterface(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface)

Example 7 with JobSubmissionInterface

use of org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface 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 8 with JobSubmissionInterface

use of org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface in project airavata by apache.

the class CreateLaunchExperiment method registerUnicoreEndpoint.

public static String registerUnicoreEndpoint(String hostName, String hostDesc, JobSubmissionProtocol protocol, SecurityProtocol securityProtocol) throws TException {
    ComputeResourceDescription computeResourceDescription = RegisterSampleApplicationsUtils.createComputeResourceDescription(hostName, hostDesc, null, null);
    fsdResourceId = airavataClient.registerComputeResource(new AuthzToken(""), computeResourceDescription);
    if (fsdResourceId.isEmpty())
        throw new AiravataClientException();
    System.out.println("FSD Compute ResourceID: " + fsdResourceId);
    JobSubmissionInterface jobSubmission = RegisterSampleApplicationsUtils.createJobSubmissionInterface(fsdResourceId, protocol, 2);
    UnicoreJobSubmission ucrJobSubmission = new UnicoreJobSubmission();
    ucrJobSubmission.setSecurityProtocol(securityProtocol);
    ucrJobSubmission.setUnicoreEndPointURL(unicoreEndPointURL);
    return jobSubmission.getJobSubmissionInterfaceId();
}
Also used : UnicoreJobSubmission(org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission) JobSubmissionInterface(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface) ComputeResourceDescription(org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription) AuthzToken(org.apache.airavata.model.security.AuthzToken)

Example 9 with JobSubmissionInterface

use of org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface in project airavata by apache.

the class GFacEngineImpl method getResourceJobManager.

public static ResourceJobManager getResourceJobManager(ProcessContext processCtx) throws AppCatalogException, GFacException {
    List<JobSubmissionInterface> jobSubmissionInterfaces = Factory.getDefaultAppCatalog().getComputeResource().getComputeResource(processCtx.getComputeResourceId()).getJobSubmissionInterfaces();
    ResourceJobManager resourceJobManager = null;
    JobSubmissionInterface jsInterface = null;
    for (JobSubmissionInterface jobSubmissionInterface : jobSubmissionInterfaces) {
        if (jobSubmissionInterface.getJobSubmissionProtocol() == processCtx.getJobSubmissionProtocol()) {
            jsInterface = jobSubmissionInterface;
            break;
        }
    }
    if (jsInterface == null) {
        throw new GFacException("Job Submission interface cannot be empty at this point");
    } else if (jsInterface.getJobSubmissionProtocol() == JobSubmissionProtocol.SSH) {
        SSHJobSubmission sshJobSubmission = Factory.getDefaultAppCatalog().getComputeResource().getSSHJobSubmission(jsInterface.getJobSubmissionInterfaceId());
        // fixme - Move this to populate process
        processCtx.setMonitorMode(sshJobSubmission.getMonitorMode());
        // context method.
        resourceJobManager = sshJobSubmission.getResourceJobManager();
    } else if (jsInterface.getJobSubmissionProtocol() == JobSubmissionProtocol.LOCAL) {
        LOCALSubmission localSubmission = Factory.getDefaultAppCatalog().getComputeResource().getLocalJobSubmission(jsInterface.getJobSubmissionInterfaceId());
        resourceJobManager = localSubmission.getResourceJobManager();
    } else if (jsInterface.getJobSubmissionProtocol() == JobSubmissionProtocol.SSH_FORK) {
        SSHJobSubmission sshJobSubmission = Factory.getDefaultAppCatalog().getComputeResource().getSSHJobSubmission(jsInterface.getJobSubmissionInterfaceId());
        // fixme - Move this to populate process
        processCtx.setMonitorMode(sshJobSubmission.getMonitorMode());
        resourceJobManager = sshJobSubmission.getResourceJobManager();
    } else if (jsInterface.getJobSubmissionProtocol() == JobSubmissionProtocol.CLOUD) {
        return null;
    } else {
        throw new GFacException("Unsupported JobSubmissionProtocol - " + jsInterface.getJobSubmissionProtocol().name());
    }
    if (resourceJobManager == null) {
        throw new GFacException("Resource Job Manager is empty.");
    }
    return resourceJobManager;
}
Also used : LOCALSubmission(org.apache.airavata.model.appcatalog.computeresource.LOCALSubmission) JobSubmissionInterface(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface) GFacException(org.apache.airavata.gfac.core.GFacException) ResourceJobManager(org.apache.airavata.model.appcatalog.computeresource.ResourceJobManager) SSHJobSubmission(org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission)

Aggregations

JobSubmissionInterface (org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface)9 ComputeResourceDescription (org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription)4 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)3 UnicoreJobSubmission (org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission)3 ComputeResourcePreference (org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference)3 GFacException (org.apache.airavata.gfac.core.GFacException)2 SSHJobSubmission (org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission)2 UserComputeResourcePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference)2 AuthzToken (org.apache.airavata.model.security.AuthzToken)2 RegistryService (org.apache.airavata.registry.api.RegistryService)2 TException (org.apache.thrift.TException)2 Channel (com.jcraft.jsch.Channel)1 ChannelExec (com.jcraft.jsch.ChannelExec)1 JSch (com.jcraft.jsch.JSch)1 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 ActivityClient (de.fzj.unicore.bes.client.ActivityClient)1 FactoryClient (de.fzj.unicore.bes.client.FactoryClient)1 StorageClient (de.fzj.unicore.uas.client.StorageClient)1 IOException (java.io.IOException)1