Ejemplo n.º 1
0
 public TopologyTemplate searchTopologyTemplateByName(String name) {
   Map<String, String[]> filters =
       MapUtil.newHashMap(new String[] {"name"}, new String[][] {new String[] {name}});
   GetMultipleDataResult<TopologyTemplate> result =
       alienDAO.find(TopologyTemplate.class, filters, Integer.MAX_VALUE);
   if (result.getTotalResults() > 0) {
     return result.getData()[0];
   }
   return null;
 }
  private Deployment getActiveDeployment() {
    Deployment deployment = null;

    GetMultipleDataResult<Deployment> dataResult =
        dao.search(
            Deployment.class,
            null,
            MapUtil.newHashMap(
                new String[] {"cloudId", "endDate"},
                new String[][] {new String[] {cloudId}, new String[] {null}}),
            1);
    if (dataResult.getData() != null && dataResult.getData().length > 0) {
      deployment = dataResult.getData()[0];
    }
    return deployment;
  }
  /**
   * Create a new instance of the {@link PaaSProviderPollingMonitor} to monitor the given paas
   * provider.
   *
   * @param paaSProvider The paas provider to monitor.
   */
  @SuppressWarnings("rawtypes")
  public PaaSProviderPollingMonitor(
      IGenericSearchDAO dao,
      IGenericSearchDAO monitorDAO,
      IPaaSProvider paaSProvider,
      List<IPaasEventListener> listeners,
      String cloudId) {
    this.cloudId = cloudId;
    this.dao = dao;
    this.monitorDAO = monitorDAO;
    this.paaSProvider = paaSProvider;
    this.listeners = listeners;
    Set<Class<?>> eventClasses = Sets.newHashSet();
    try {
      eventClasses = TypeScanner.scanTypes("alien4cloud.paas.model", AbstractMonitorEvent.class);
    } catch (ClassNotFoundException e) {
      log.info("No event class derived from {} found", AbstractMonitorEvent.class.getName());
    }
    Map<String, String[]> filter = Maps.newHashMap();
    filter.put("cloudId", new String[] {this.cloudId});
    // sort by filed date DESC
    SearchQueryHelperBuilder searchQueryHelperBuilder =
        monitorDAO
            .getQueryHelper()
            .buildSearchQuery("deploymentmonitorevents")
            .types(eventClasses.toArray(new Class<?>[eventClasses.size()]))
            .filters(filter)
            .fieldSort("date", true);

    // the first one is the one with the latest date
    GetMultipleDataResult lastestEventResult = monitorDAO.search(searchQueryHelperBuilder, 0, 1);
    if (lastestEventResult.getData().length > 0) {
      AbstractMonitorEvent lastEvent = (AbstractMonitorEvent) lastestEventResult.getData()[0];
      Date lastEventDate = new Date(lastEvent.getDate());
      log.info(
          "Recovering events from the last in elasticsearch {} of type {}",
          lastEventDate,
          lastEvent.getClass().getName());
      this.lastPollingDate = lastEventDate;
    } else {
      this.lastPollingDate = new Date();
      log.debug(
          "No monitor events found, the last polling date will be current date {}",
          this.lastPollingDate);
    }
    paaSEventsCallback = new PaaSEventsCallback();
  }