<commit_before>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/
package org.apache.airavata.gfac.impl.job;

import org.apache.airavata.gfac.core.JobManagerConfiguration;
import org.apache.airavata.gfac.core.cluster.OutputParser;
import org.apache.airavata.gfac.core.cluster.RawCommandInfo;
import org.apache.airavata.model.appcatalog.computeresource.JobManagerCommand;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.util.Map;

public class SlurmJobConfiguration implements JobManagerConfiguration {
	private final Map<JobManagerCommand, String> jobManagerCommands;
    private String jobDescriptionTemplateName;
    private String scriptExtension;
    private String installedPath;
    private OutputParser parser;

    public SlurmJobConfiguration(String jobDescriptionTemplateName,
                                 String scriptExtension, String installedPath, Map<JobManagerCommand, String>
		                                 jobManagerCommands, OutputParser parser) {
        this.jobDescriptionTemplateName = jobDescriptionTemplateName;
        this.scriptExtension = scriptExtension;
        this.parser = parser;
        if (installedPath.endsWith("/")) {
            this.installedPath = installedPath;
        } else {
            this.installedPath = installedPath + "/";
        }
	    this.jobManagerCommands = jobManagerCommands;
    }

    public RawCommandInfo getCancelCommand(String jobID) {
        return new RawCommandInfo(this.installedPath + "scancel " + jobID);
    }

    public String getJobDescriptionTemplateName() {
        return jobDescriptionTemplateName;
    }

    public void setJobDescriptionTemplateName(String jobDescriptionTemplateName) {
        this.jobDescriptionTemplateName = jobDescriptionTemplateName;
    }

    public RawCommandInfo getMonitorCommand(String jobID) {
        return new RawCommandInfo(this.installedPath + "squeue -j " + jobID);
    }

    public String getScriptExtension() {
        return scriptExtension;
    }

    public RawCommandInfo getSubmitCommand(String workingDirectory,String pbsFilePath) {
          return new RawCommandInfo(this.installedPath + "sbatch " +
                workingDirectory + File.separator + FilenameUtils.getName(pbsFilePath));
    }

    public String getInstalledPath() {
        return installedPath;
    }

    public void setInstalledPath(String installedPath) {
        this.installedPath = installedPath;
    }

    public OutputParser getParser() {
        return parser;
    }

    public void setParser(OutputParser parser) {
        this.parser = parser;
    }

    public RawCommandInfo getUserBasedMonitorCommand(String userName) {
        return new RawCommandInfo(this.installedPath + "squeue -u " + userName);
    }

    @Override
    public RawCommandInfo getJobIdMonitorCommand(String jobName, String userName) {
        return new RawCommandInfo(this.installedPath + "squeue -n " + jobName + " -u " + userName);
    }

    @Override
    public String getBaseCancelCommand() {
        return "scancel";
    }

    @Override
    public String getBaseMonitorCommand() {
        return "squeue";
    }

    @Override
    public String getBaseSubmitCommand() {
        return "sbatch";
    }
}
<commit_msg>Use jobmanager commands in slurm job configuraiton<commit_after>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/
package org.apache.airavata.gfac.impl.job;

import org.apache.airavata.gfac.core.JobManagerConfiguration;
import org.apache.airavata.gfac.core.cluster.OutputParser;
import org.apache.airavata.gfac.core.cluster.RawCommandInfo;
import org.apache.airavata.model.appcatalog.computeresource.JobManagerCommand;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.util.Map;

public class SlurmJobConfiguration implements JobManagerConfiguration {
	private final Map<JobManagerCommand, String> jMCommands;
    private String jobDescriptionTemplateName;
    private String scriptExtension;
    private String installedPath;
    private OutputParser parser;

    public SlurmJobConfiguration(String jobDescriptionTemplateName,
                                 String scriptExtension, String installedPath, Map<JobManagerCommand, String>
		                                 jobManagerCommands, OutputParser parser) {
        this.jobDescriptionTemplateName = jobDescriptionTemplateName;
        this.scriptExtension = scriptExtension;
        this.parser = parser;
        if (installedPath.endsWith("/")) {
            this.installedPath = installedPath;
        } else {
            this.installedPath = installedPath + "/";
        }
	    this.jMCommands = jobManagerCommands;
    }

    public RawCommandInfo getCancelCommand(String jobID) {
        return new RawCommandInfo(this.installedPath + jMCommands.get(JobManagerCommand.DELETION) + " " + jobID);
    }

    public String getJobDescriptionTemplateName() {
        return jobDescriptionTemplateName;
    }

    public void setJobDescriptionTemplateName(String jobDescriptionTemplateName) {
        this.jobDescriptionTemplateName = jobDescriptionTemplateName;
    }

    public RawCommandInfo getMonitorCommand(String jobID) {
        return new RawCommandInfo(this.installedPath + jMCommands.get(JobManagerCommand.JOB_MONITORING) + " -j " + jobID);
    }

    public String getScriptExtension() {
        return scriptExtension;
    }

    public RawCommandInfo getSubmitCommand(String workingDirectory,String pbsFilePath) {
          return new RawCommandInfo(this.installedPath + jMCommands.get(JobManagerCommand.SUBMISSION) + " " +
                workingDirectory + File.separator + FilenameUtils.getName(pbsFilePath));
    }

    public String getInstalledPath() {
        return installedPath;
    }

    public void setInstalledPath(String installedPath) {
        this.installedPath = installedPath;
    }

    public OutputParser getParser() {
        return parser;
    }

    public void setParser(OutputParser parser) {
        this.parser = parser;
    }

    public RawCommandInfo getUserBasedMonitorCommand(String userName) {
        return new RawCommandInfo(this.installedPath + jMCommands.get(JobManagerCommand.JOB_MONITORING) + " -u " + userName);
    }

    @Override
    public RawCommandInfo getJobIdMonitorCommand(String jobName, String userName) {
        return new RawCommandInfo(this.installedPath + jMCommands.get(JobManagerCommand.JOB_MONITORING) + " -n " + jobName + " -u " + userName);
    }

    @Override
    public String getBaseCancelCommand() {
	    return jMCommands.get(JobManagerCommand.DELETION);
    }

    @Override
    public String getBaseMonitorCommand() {
        return jMCommands.get(JobManagerCommand.JOB_MONITORING);
    }

    @Override
    public String getBaseSubmitCommand() {
        return jMCommands.get(JobManagerCommand.SUBMISSION);
    }
}

{'fraction_non_alphanumeric': 0.07398111629018764, 'fraction_numerical': 0.0009561372056890164, 'mean_word_length': 3.3765690376569037, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1571252', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2141, 'n_words': 586}