gt:         return this.client.submit(job, variables, headerParams);
context: /*
   * ProActive Parallel Suite(TM):
   * The Open Source library for parallel and distributed
   * Workflows & Scheduling, Orchestration, Cloud Automation
   * and Big Data Analysis on Enterprise Grids & Clouds.
   *
   * Copyright (c) 2007 - 2017 ActiveEon
   * Contact: contact@activeeon.com
   *
   * This library is free software: you can redistribute it and/or
   * modify it under the terms of the GNU Affero General Public License
   * as published by the Free Software Foundation: version 3 of
   * the License.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Affero General Public License for more details.
   *
   * You should have received a copy of the GNU Affero General Public License
   * along with this program. If not, see <http://www.gnu.org/licenses/>.
   *
   * If needed, contact us to obtain a release under GPL Version 2 or 3
   * or a different license than the AGPL.
   */
  package org.ow2.proactive.scheduler.task.client;
  
  import java.io.File;
  import java.io.Serializable;
  import java.net.URL;
  import java.security.KeyException;
  import java.util.Date;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.concurrent.TimeoutException;
  
  import org.objectweb.proactive.annotation.PublicAPI;
  import org.ow2.proactive.authentication.ConnectionInfo;
  import org.ow2.proactive.authentication.UserData;
  import org.ow2.proactive.authentication.crypto.CredData;
  import org.ow2.proactive.db.SortParameter;
  import org.ow2.proactive.scheduler.common.JobFilterCriteria;
  import org.ow2.proactive.scheduler.common.JobSortParameter;
  import org.ow2.proactive.scheduler.common.Page;
  import org.ow2.proactive.scheduler.common.SchedulerEvent;
  import org.ow2.proactive.scheduler.common.SchedulerEventListener;
  import org.ow2.proactive.scheduler.common.SchedulerState;
  import org.ow2.proactive.scheduler.common.SchedulerStatus;
  import org.ow2.proactive.scheduler.common.SortSpecifierContainer;
  import org.ow2.proactive.scheduler.common.TaskDescriptor;
  import org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException;
  import org.ow2.proactive.scheduler.common.exception.JobCreationException;
  import org.ow2.proactive.scheduler.common.exception.NotConnectedException;
  import org.ow2.proactive.scheduler.common.exception.PermissionException;
  import org.ow2.proactive.scheduler.common.exception.SubmissionClosedException;
  import org.ow2.proactive.scheduler.common.exception.UnknownJobException;
  import org.ow2.proactive.scheduler.common.exception.UnknownTaskException;
  import org.ow2.proactive.scheduler.common.job.Job;
  import org.ow2.proactive.scheduler.common.job.JobId;
  import org.ow2.proactive.scheduler.common.job.JobInfo;
  import org.ow2.proactive.scheduler.common.job.JobPriority;
  import org.ow2.proactive.scheduler.common.job.JobResult;
  import org.ow2.proactive.scheduler.common.job.JobState;
  import org.ow2.proactive.scheduler.common.task.TaskId;
  import org.ow2.proactive.scheduler.common.task.TaskResult;
  import org.ow2.proactive.scheduler.common.task.TaskState;
  import org.ow2.proactive.scheduler.common.usage.JobUsage;
  import org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider;
  import org.ow2.proactive.scheduler.job.SchedulerUserInfo;
  import org.ow2.proactive.scheduler.rest.ISchedulerClient;
  import org.ow2.proactive.scheduler.rest.SchedulerClient;
  import org.ow2.proactive.scheduler.task.utils.Decrypter;
  
  
  /**
   * Scheduler api available as a variable during the execution of a task. it is based on the ISchedulerClient interface.
   *
   * @author ActiveEon Team
   */
  @PublicAPI
  public class SchedulerNodeClient implements ISchedulerClient, Serializable {
  
      private Decrypter decrypter;
  
      private String schedulerRestUrl;
  
      private transient ISchedulerClient client = null;
  
      public SchedulerNodeClient(Decrypter decrypter, String schedulerRestUrl) {
          SchedulerNodeClient.this.decrypter = decrypter;
          SchedulerNodeClient.this.schedulerRestUrl = schedulerRestUrl;
      }
  
      /**
       * Connects to the scheduler at the default schedulerRestUrl, using the current user credentials
       *
       * @throws Exception
       */
      public void connect() throws Exception {
          connect(SchedulerNodeClient.this.schedulerRestUrl);
      }
  
      /**
       * Connects to the scheduler at the specified schedulerRestUrl, using the current user credentials
       * @param url schedulerRestUrl of the scheduler
       * @throws Exception
       */
      public void connect(String url) throws Exception {
          CredData userCreds = decrypter.decrypt();
          client = SchedulerClient.createInstance();
          client.init(new ConnectionInfo(url, userCreds.getLogin(), userCreds.getPassword(), null, true));
      }
  
      @Override
      public List<JobUsage> getMyAccountUsage(Date startDate, Date endDate)
              throws NotConnectedException, PermissionException {
          renewSession();
          return client.getMyAccountUsage(startDate, endDate);
      }
  
      @Override
      public List<JobUsage> getAccountUsage(String user, Date startDate, Date endDate)
              throws NotConnectedException, PermissionException {
          renewSession();
          return client.getAccountUsage(user, startDate, endDate);
      }
  
      @Override
      public List<String> getUserSpaceURIs() throws NotConnectedException, PermissionException {
          renewSession();
          return client.getUserSpaceURIs();
      }
  
      @Override
      public List<String> getGlobalSpaceURIs() throws NotConnectedException, PermissionException {
          renewSession();
          return client.getGlobalSpaceURIs();
      }
  
      @Override
      public JobResult getJobResult(JobId jobId) throws NotConnectedException, PermissionException, UnknownJobException {
          renewSession();
          return client.getJobResult(jobId);
      }
  
      @Override
      public TaskResult getTaskResultFromIncarnation(JobId jobId, String taskName, int inc)
              throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
          renewSession();
          return client.getTaskResultFromIncarnation(jobId, taskName, inc);
      }
  
      @Override
      public boolean killTask(JobId jobId, String taskName)
              throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
          renewSession();
          return client.killTask(jobId, taskName);
      }
  
      @Override
      public boolean restartTask(JobId jobId, String taskName, int restartDelay)
              throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
          renewSession();
          return client.restartTask(jobId, taskName, restartDelay);
      }
  
      @Override
      public boolean preemptTask(JobId jobId, String taskName, int restartDelay)
              throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
          renewSession();
          return client.preemptTask(jobId, taskName, restartDelay);
      }
  
      @Override
      public boolean removeJob(JobId jobId) throws NotConnectedException, UnknownJobException, PermissionException {
          renewSession();
          return client.removeJob(jobId);
      }
  
      @Override
      public void listenJobLogs(JobId jobId, AppenderProvider appenderProvider)
              throws NotConnectedException, UnknownJobException, PermissionException {
          renewSession();
          client.listenJobLogs(jobId, appenderProvider);
      }
  
      @Override
      public boolean killJob(JobId jobId) throws NotConnectedException, UnknownJobException, PermissionException {
          renewSession();
          return client.killJob(jobId);
      }
  
      @Override
      public boolean pauseJob(JobId jobId) throws NotConnectedException, UnknownJobException, PermissionException {
          renewSession();
          return client.pauseJob(jobId);
      }
  
      @Override
      public boolean resumeJob(JobId jobId) throws NotConnectedException, UnknownJobException, PermissionException {
          renewSession();
          return client.resumeJob(jobId);
      }
  
      @Override
      public void changeJobPriority(JobId jobId, JobPriority priority)
              throws NotConnectedException, UnknownJobException, PermissionException, JobAlreadyFinishedException {
          renewSession();
          client.changeJobPriority(jobId, priority);
      }
  
      @Override
      public boolean changePolicy(String policyClassName) throws NotConnectedException, PermissionException {
          renewSession();
          return client.changePolicy(policyClassName);
      }
  
      @Override
      public boolean start() throws NotConnectedException, PermissionException {
          renewSession();
          return client.start();
      }
  
      @Override
      public boolean stop() throws NotConnectedException, PermissionException {
          renewSession();
          return client.stop();
      }
  
      @Override
      public boolean pause() throws NotConnectedException, PermissionException {
          renewSession();
          return client.pause();
      }
  
      @Override
      public boolean freeze() throws NotConnectedException, PermissionException {
          renewSession();
          return client.freeze();
      }
  
      @Override
      public boolean resume() throws NotConnectedException, PermissionException {
          renewSession();
          return client.resume();
      }
  
      @Override
      public boolean shutdown() throws NotConnectedException, PermissionException {
          renewSession();
          return client.shutdown();
      }
  
      @Override
      public boolean kill() throws NotConnectedException, PermissionException {
          renewSession();
          return client.kill();
      }
  
      @Override
      public boolean linkResourceManager(String rmURL) throws NotConnectedException, PermissionException {
          renewSession();
          return client.linkResourceManager(rmURL);
      }
  
      @Override
      public boolean reloadPolicyConfiguration() throws NotConnectedException, PermissionException {
          renewSession();
          return client.reloadPolicyConfiguration();
      }
  
      @Override
      public JobId submit(Job job)
              throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
          renewSession();
          return client.submit(job);
      }
  
      @Override
      public JobId submit(File job)
              throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
          renewSession();
          return client.submit(job);
      }
  
      @Override
      public JobId submit(URL job)
              throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
          renewSession();
          return client.submit(job);
      }
  
      @Override
      public JobId submitFromCatalog(String catalogRestURL, String bucketName, String workflowName)
              throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
          renewSession();
          return client.submitFromCatalog(catalogRestURL, bucketName, workflowName);
      }
  
      @Override
      public JobId submit(URL job, Map<String, String> variables, Map<String, String> headerParams)
              throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
          if (client == null)
              throw new NotConnectedException("Client not connected, call connect() before using the scheduler client");
  