Ejemplo n.º 1
0
  private void updateData(List<OctopusApplication> octopusApplications) {
    for (OctopusApplication application : octopusApplications) {
      List<EnvironmentComponent> compList = new ArrayList<>();
      List<EnvironmentStatus> statusList = new ArrayList<>();
      long startApp = System.currentTimeMillis();

      List<ApplicationDeploymentHistoryItem> applicationDeploymentHistoryItems =
          octopusClient.getApplicationDeploymentHistory(application);

      LOGGER.info("history ==>" + applicationDeploymentHistoryItems.size());

      compList.addAll(getEnvironmentComponent(applicationDeploymentHistoryItems));

      statusList.addAll(getEnvironmentStatus(applicationDeploymentHistoryItems));

      LOGGER.info("compList ==>" + compList.size());

      LOGGER.info("statusList ==>" + statusList.size());

      if (!compList.isEmpty()) {
        List<EnvironmentComponent> existingComponents =
            envComponentRepository.findByCollectorItemId(application.getId());
        envComponentRepository.delete(existingComponents);
        envComponentRepository.save(compList);
      }
      if (!statusList.isEmpty()) {
        List<EnvironmentStatus> existingStatuses =
            environmentStatusRepository.findByCollectorItemId(application.getId());
        environmentStatusRepository.delete(existingStatuses);
        environmentStatusRepository.save(statusList);
      }

      log(" " + application.getApplicationName(), startApp);
    }
  }
Ejemplo n.º 2
0
  private void addNewApplications(
      List<OctopusApplication> applications, OctopusCollector collector) {
    long start = System.currentTimeMillis();
    int count = 0;

    log("All apps", start, applications.size());
    for (OctopusApplication application : applications) {

      if (isNewApplication(collector, application)) {
        application.setCollectorId(collector.getId());
        application.setEnabled(false);
        application.setDescription(application.getApplicationName());
        try {
          octopusApplicationRepository.save(application);
        } catch (org.springframework.dao.DuplicateKeyException ce) {
          log("Duplicates items not allowed", 0);
        }
        count++;
      }
    }
    log("New apps", start, count);
  }
Ejemplo n.º 3
0
 /**
  * Clean up unused deployment collector items
  *
  * @param collector the {@link UDeployCollector}
  */
 @SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts")
 private void clean(OctopusCollector collector) {
   deleteUnwantedJobs(collector);
   Set<ObjectId> uniqueIDs = new HashSet<>();
   for (com.capitalone.dashboard.model.Component comp : dbComponentRepository.findAll()) {
     if (comp.getCollectorItems() == null || comp.getCollectorItems().isEmpty()) continue;
     List<CollectorItem> itemList = comp.getCollectorItems().get(CollectorType.Deployment);
     if (itemList == null) continue;
     for (CollectorItem ci : itemList) {
       if (ci == null) continue;
       uniqueIDs.add(ci.getId());
     }
   }
   List<OctopusApplication> appList = new ArrayList<>();
   Set<ObjectId> udId = new HashSet<>();
   udId.add(collector.getId());
   for (OctopusApplication app : octopusApplicationRepository.findByCollectorIdIn(udId)) {
     if (app != null) {
       app.setEnabled(uniqueIDs.contains(app.getId()));
       appList.add(app);
     }
   }
   octopusApplicationRepository.save(appList);
 }
Ejemplo n.º 4
0
 private boolean isNewApplication(OctopusCollector collector, OctopusApplication application) {
   return octopusApplicationRepository.findUDeployApplication(
           collector.getId(), octopusSettings.getUrl(), application.getApplicationId())
       == null;
 }