示例#1
0
 /** @param jobEvent */
 public void observe(@Observes(notifyObserver = Reception.ALWAYS) JobEvent jobEvent) {
   if (jobEvent.getEvent() == JobLifecycleEvent.AGENT_STARTED) {
     JobInstance job = dao.findById(Integer.valueOf(jobEvent.getJobId()));
     for (EntityVersion version : job.getNotificationVersions()) {
       JobNotification not = notificationDao.findById(version.getObjectId());
       if (not != null
           && not.getLifecycleEvents() != null
           && not.getLifecycleEvents().contains(JobLifecycleEvent.AGENT_EXCESSIVE_CPU)) {
         LOG.info("Adding watches for job " + job.getId());
         addWatches(job, not);
         break;
       }
     }
   } else if (jobEvent.getEvent() == JobLifecycleEvent.JOB_FINISHED) {
     JobInstance job = dao.findById(Integer.valueOf(jobEvent.getJobId()));
     for (EntityVersion version : job.getNotificationVersions()) {
       JobNotification not = notificationDao.findById(version.getObjectId());
       if (not != null
           && not.getLifecycleEvents() != null
           && not.getLifecycleEvents().contains(JobLifecycleEvent.AGENT_EXCESSIVE_CPU)) {
         LOG.info("Adding watches for job " + job.getId());
         removeWatches(job, not);
         break;
       }
     }
   }
 }
示例#2
0
 private JobRequest jobToJobRequest(JobInstance job) {
   Builder builder = JobRequestImpl.builder();
   builder
       .withBaselineVirtualUsers(job.getBaselineVirtualUsers())
       .withId(Integer.toString(job.getId()))
       .withIncrementStrategy(job.getIncrementStrategy())
       .withLocation(job.getLocation())
       .withRampTime(job.getRampTime())
       .withLoggingProfile(job.getLoggingProfile())
       .withStopBehavior(job.getStopBehavior())
       .withReportingMode(job.getReportingMode())
       .withUseEips(job.isUseEips())
       .withVmInstanceType(job.getVmInstanceType())
       .withnumUsersPerAgent(job.getNumUsersPerAgent())
       .withSimulationTime(job.getSimulationTime())
       .withStatus(job.getStatus())
       .withTerminationPolicy(job.getTerminationPolicy())
       .withUserIntervalIncrement(job.getUserIntervalIncrement());
   builder.withRegions(getRegions(job));
   builder.withNofitications(getNotifications(job));
   builder.withDataFileIds(getDataFileIds(job));
   if (job.getTerminationPolicy() == TerminationPolicy.script) {
     builder.withSimulationTime(0);
   }
   Workload workload = new WorkloadDao().findById(job.getWorkloadId());
   builder.withScriptXmlUrl(buildScriptXml(Integer.toString(job.getId()), workload));
   return builder.build();
 }
示例#3
0
  /**
   * @param jobId
   * @param mailService
   */
  private void checkJobStatus(String jobId, MailService mailService) {
    CloudVmStatusContainer container = tracker.getVmStatusForJob(jobId);
    LOG.info(
        "Checking Job Status to see if we can kill reporting instances. Container=" + container);
    if (container != null) {
      if (container.getEndTime() != null) {
        JobInstanceDao dao = new JobInstanceDao();
        // hack to see if this is an automatino job

        // set the status of the JobInstance to finished.
        JobInstance finishedJob = dao.findById(Integer.valueOf(jobId));
        if (finishedJob.getEndTime() == null) {
          finishedJob.setEndTime(new Date());
          finishedJob.setStatus(JobQueueStatus.Completed);
          dao.saveOrUpdate(finishedJob);
        }
        List<JobQueueStatus> statuses =
            Arrays.asList(new JobQueueStatus[] {JobQueueStatus.Running, JobQueueStatus.Starting});
        List<JobInstance> instances = dao.getForStatus(statuses);
        LOG.info(
            "Checking Job Status to see if we can kill reporting instances. found running instances: "
                + instances.size());
        boolean killModal = true;
        boolean killNonRegional = true;

        for (JobInstance job : instances) {
          CloudVmStatusContainer statusForJob =
              tracker.getVmStatusForJob(Integer.toString(job.getId()));
          if (!jobId.equals(Integer.toString(job.getId()))
              && statusForJob != null
              && statusForJob.getEndTime() == null) {
            LOG.info("Found another job that is not finished: " + job);
          }
        }
        if (killNonRegional || killModal) {
          for (CloudVmStatusContainer statusForJob : tracker.getAllJobs()) {
            if (statusForJob.getEndTime() == null
                && !NumberUtils.isNumber(statusForJob.getJobId())) {
              killNonRegional = false;
              killModal = false;
              LOG.info(
                  "Cannot kill Reporting instances because of automation job id: "
                      + statusForJob.getJobId());
            }
          }
        }
      } else {
        LOG.info("Container does not have end time set so cannot kill reporting instaces.");
      }
    }
  }
示例#4
0
 /** @param all */
 private void filterDate(List<JobInstance> all) {
   Date date = jobReportOptions.getStartTime();
   if (date != null) {
     for (Iterator<JobInstance> iter = all.iterator(); iter.hasNext(); ) {
       JobInstance job = iter.next();
       Date st = job.getStartTime() != null ? job.getStartTime() : job.getCreated();
       if (!date.before(st)) {
         iter.remove();
       }
     }
   }
   date = jobReportOptions.getEndTime();
   if (date != null) {
     for (Iterator<JobInstance> iter = all.iterator(); iter.hasNext(); ) {
       JobInstance job = iter.next();
       Date st = job.getStartTime() != null ? job.getStartTime() : job.getCreated();
       if (!date.after(st)) {
         iter.remove();
       }
     }
   }
   if (NumberUtils.isDigits(jobReportOptions.getMinUsers())) {
     try {
       int users = Integer.parseInt(jobReportOptions.getMinUsers());
       for (Iterator<JobInstance> iter = all.iterator(); iter.hasNext(); ) {
         JobInstance job = iter.next();
         if (job.getTotalVirtualUsers() < users) {
           iter.remove();
         }
       }
     } catch (NumberFormatException e) {
       LOG.warn("Error with min users value of " + jobReportOptions.getMinUsers());
     }
   }
   if (NumberUtils.isDigits(jobReportOptions.getMaxUsers())) {
     try {
       int users = Integer.parseInt(jobReportOptions.getMaxUsers());
       for (Iterator<JobInstance> iter = all.iterator(); iter.hasNext(); ) {
         JobInstance job = iter.next();
         if (job.getTotalVirtualUsers() > users) {
           iter.remove();
         }
       }
     } catch (NumberFormatException e) {
       LOG.warn("Error with max users value of " + jobReportOptions.getMaxUsers());
     }
   }
   if (NumberUtils.isDigits(jobReportOptions.getJobIdStart())) {
     try {
       int jobIdStart = NumberUtils.toInt(jobReportOptions.getJobIdStart());
       for (Iterator<JobInstance> iter = all.iterator(); iter.hasNext(); ) {
         JobInstance job = iter.next();
         if (job.getId() < jobIdStart) {
           iter.remove();
         }
       }
     } catch (NumberFormatException e) {
       LOG.warn("Error with max users value of " + jobReportOptions.getMaxUsers());
     }
   }
   if (NumberUtils.isDigits(jobReportOptions.getJobIdEnd())) {
     try {
       int jobIdStart = NumberUtils.toInt(jobReportOptions.getJobIdEnd());
       for (Iterator<JobInstance> iter = all.iterator(); iter.hasNext(); ) {
         JobInstance job = iter.next();
         if (job.getId() > jobIdStart) {
           iter.remove();
         }
       }
     } catch (NumberFormatException e) {
       LOG.warn("Error with max users value of " + jobReportOptions.getMaxUsers());
     }
   }
 }