Esempio n. 1
0
  @PostConstruct
  protected void init() {
    AllFieldsSearch = createSearchBuilder();
    AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), Op.EQ);
    AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), Op.EQ);
    AllFieldsSearch.and("role", AllFieldsSearch.entity().getRole(), Op.EQ);
    AllFieldsSearch.and("domainId", AllFieldsSearch.entity().getDomainId(), Op.EQ);
    AllFieldsSearch.and("host", AllFieldsSearch.entity().getHostId(), Op.EQ);
    AllFieldsSearch.and("lastHost", AllFieldsSearch.entity().getLastHostId(), Op.EQ);
    AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
    AllFieldsSearch.and("states", AllFieldsSearch.entity().getState(), Op.IN);
    SearchBuilder<RouterNetworkVO> joinRouterNetwork = _routerNetworkDao.createSearchBuilder();
    joinRouterNetwork.and("networkId", joinRouterNetwork.entity().getNetworkId(), Op.EQ);
    AllFieldsSearch.join(
        "networkRouter",
        joinRouterNetwork,
        joinRouterNetwork.entity().getRouterId(),
        AllFieldsSearch.entity().getId(),
        JoinType.INNER);
    AllFieldsSearch.and("podId", AllFieldsSearch.entity().getPodIdToDeployIn(), Op.EQ);
    AllFieldsSearch.and("elementId", AllFieldsSearch.entity().getElementId(), Op.EQ);
    AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
    AllFieldsSearch.done();

    VpcSearch = createSearchBuilder();
    VpcSearch.and("role", VpcSearch.entity().getRole(), Op.EQ);
    VpcSearch.and("vpcId", VpcSearch.entity().getVpcId(), Op.EQ);
    VpcSearch.done();

    IdNetworkIdStatesSearch = createSearchBuilder();
    IdNetworkIdStatesSearch.and("id", IdNetworkIdStatesSearch.entity().getId(), Op.EQ);
    SearchBuilder<RouterNetworkVO> joinRouterNetwork1 = _routerNetworkDao.createSearchBuilder();
    joinRouterNetwork1.and("networkId", joinRouterNetwork1.entity().getNetworkId(), Op.EQ);
    IdNetworkIdStatesSearch.join(
        "networkRouter",
        joinRouterNetwork1,
        joinRouterNetwork1.entity().getRouterId(),
        IdNetworkIdStatesSearch.entity().getId(),
        JoinType.INNER);
    IdNetworkIdStatesSearch.and("states", IdNetworkIdStatesSearch.entity().getState(), Op.IN);
    IdNetworkIdStatesSearch.done();

    HostUpSearch = createSearchBuilder();
    HostUpSearch.select(null, Func.DISTINCT, HostUpSearch.entity().getId());
    HostUpSearch.and("host", HostUpSearch.entity().getHostId(), Op.EQ);
    HostUpSearch.and("states", HostUpSearch.entity().getState(), Op.NIN);
    SearchBuilder<RouterNetworkVO> joinRouterNetwork3 = _routerNetworkDao.createSearchBuilder();
    joinRouterNetwork3.and("networkId", joinRouterNetwork3.entity().getNetworkId(), Op.EQ);
    joinRouterNetwork3.and("type", joinRouterNetwork3.entity().getGuestType(), Op.EQ);
    HostUpSearch.join(
        "networkRouter",
        joinRouterNetwork3,
        joinRouterNetwork3.entity().getRouterId(),
        HostUpSearch.entity().getId(),
        JoinType.INNER);
    HostUpSearch.done();

    StateNetworkTypeSearch = createSearchBuilder();
    StateNetworkTypeSearch.select(null, Func.DISTINCT, StateNetworkTypeSearch.entity().getId());
    StateNetworkTypeSearch.and("state", StateNetworkTypeSearch.entity().getState(), Op.EQ);
    SearchBuilder<RouterNetworkVO> joinRouterNetwork4 = _routerNetworkDao.createSearchBuilder();
    joinRouterNetwork4.and("networkId", joinRouterNetwork4.entity().getNetworkId(), Op.EQ);
    joinRouterNetwork4.and("type", joinRouterNetwork4.entity().getGuestType(), Op.EQ);
    StateNetworkTypeSearch.join(
        "networkRouter",
        joinRouterNetwork4,
        joinRouterNetwork4.entity().getRouterId(),
        StateNetworkTypeSearch.entity().getId(),
        JoinType.INNER);

    SearchBuilder<HostVO> joinHost = _hostsDao.createSearchBuilder();
    joinHost.and("mgmtServerId", joinHost.entity().getManagementServerId(), Op.EQ);
    StateNetworkTypeSearch.join(
        "host",
        joinHost,
        joinHost.entity().getId(),
        StateNetworkTypeSearch.entity().getHostId(),
        JoinType.INNER);
    StateNetworkTypeSearch.done();

    SearchByStateAndManagementServerId = createSearchBuilder();
    SearchByStateAndManagementServerId.and(
        "state", SearchByStateAndManagementServerId.entity().getState(), Op.EQ);

    SearchBuilder<HostVO> joinHost2 = _hostsDao.createSearchBuilder();
    joinHost2.and("mgmtServerId", joinHost2.entity().getManagementServerId(), Op.EQ);
    SearchByStateAndManagementServerId.join(
        "host",
        joinHost2,
        joinHost2.entity().getId(),
        SearchByStateAndManagementServerId.entity().getHostId(),
        JoinType.INNER);
    SearchByStateAndManagementServerId.done();

    OutsidePodSearch = createSearchBuilder();
    SearchBuilder<RouterNetworkVO> joinRouterNetwork2 = _routerNetworkDao.createSearchBuilder();
    joinRouterNetwork2.and("networkId", joinRouterNetwork2.entity().getNetworkId(), Op.EQ);
    OutsidePodSearch.join(
        "networkRouter",
        joinRouterNetwork2,
        joinRouterNetwork2.entity().getRouterId(),
        OutsidePodSearch.entity().getId(),
        JoinType.INNER);
    OutsidePodSearch.and("podId", OutsidePodSearch.entity().getPodIdToDeployIn(), Op.NEQ);
    OutsidePodSearch.and("state", OutsidePodSearch.entity().getState(), Op.EQ);
    OutsidePodSearch.and("role", OutsidePodSearch.entity().getRole(), Op.EQ);
    OutsidePodSearch.done();

    clusterSearch = createSearchBuilder();
    clusterSearch.and("state", clusterSearch.entity().getState(), Op.EQ);
    SearchBuilder<HostVO> clusterHost = _hostsDao.createSearchBuilder();
    clusterHost.and("clusterId", clusterHost.entity().getClusterId(), Op.EQ);
    clusterSearch.join(
        "host",
        clusterHost,
        clusterSearch.entity().getHostId(),
        clusterHost.entity().getId(),
        JoinType.INNER);
    clusterSearch.done();

    RunningSearch = createSearchBuilder();
    RunningSearch.and("dc", RunningSearch.entity().getDataCenterId(), Op.EQ);
    RunningSearch.and("account", RunningSearch.entity().getAccountId(), Op.EQ);
    RunningSearch.and("domainId", RunningSearch.entity().getDomainId(), Op.EQ);
    RunningSearch.and("state", RunningSearch.entity().getState(), Op.EQ);
    RunningSearch.and("podId", RunningSearch.entity().getPodIdToDeployIn(), Op.EQ);
    RunningSearch.done();
  }
  @Override
  public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    boolean result = super.configure(name, params);

    PublicSearch = createSearchBuilder();
    PublicSearch.and("public", PublicSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);

    routerTmpltName = (String) params.get("routing.uniquename");

    s_logger.debug("Found parameter routing unique name " + routerTmpltName);
    if (routerTmpltName == null) {
      routerTmpltName = "routing";
    }

    consoleProxyTmpltName = (String) params.get("consoleproxy.uniquename");
    if (consoleProxyTmpltName == null) {
      consoleProxyTmpltName = "routing";
    }
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("Use console proxy template : " + consoleProxyTmpltName);
    }

    UniqueNameSearch = createSearchBuilder();
    UniqueNameSearch.and(
        "uniqueName", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
    NameSearch = createSearchBuilder();
    NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);

    NameAccountIdSearch = createSearchBuilder();
    NameAccountIdSearch.and("name", NameAccountIdSearch.entity().getName(), SearchCriteria.Op.EQ);
    NameAccountIdSearch.and(
        "accountId", NameAccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);

    PublicIsoSearch = createSearchBuilder();
    PublicIsoSearch.and(
        "public", PublicIsoSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
    PublicIsoSearch.and("format", PublicIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ);
    PublicIsoSearch.and("type", PublicIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
    PublicIsoSearch.and("bootable", PublicIsoSearch.entity().isBootable(), SearchCriteria.Op.EQ);
    PublicIsoSearch.and("removed", PublicIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ);

    tmpltTypeHyperSearch = createSearchBuilder();
    tmpltTypeHyperSearch.and(
        "templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
    SearchBuilder<HostVO> hostHyperSearch = _hostDao.createSearchBuilder();
    hostHyperSearch.and("type", hostHyperSearch.entity().getType(), SearchCriteria.Op.EQ);
    hostHyperSearch.and("zoneId", hostHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    hostHyperSearch.groupBy(hostHyperSearch.entity().getHypervisorType());

    tmpltTypeHyperSearch.join(
        "tmplHyper",
        hostHyperSearch,
        hostHyperSearch.entity().getHypervisorType(),
        tmpltTypeHyperSearch.entity().getHypervisorType(),
        JoinBuilder.JoinType.INNER);
    hostHyperSearch.done();
    tmpltTypeHyperSearch.done();

    tmpltTypeHyperSearch2 = createSearchBuilder();
    tmpltTypeHyperSearch2.and(
        "templateType", tmpltTypeHyperSearch2.entity().getTemplateType(), SearchCriteria.Op.EQ);
    tmpltTypeHyperSearch2.and(
        "hypervisorType", tmpltTypeHyperSearch2.entity().getHypervisorType(), SearchCriteria.Op.EQ);

    tmpltTypeSearch = createSearchBuilder();
    tmpltTypeSearch.and(
        "templateType", tmpltTypeSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);

    AccountIdSearch = createSearchBuilder();
    AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
    AccountIdSearch.and(
        "publicTemplate", AccountIdSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
    AccountIdSearch.done();

    SearchBuilder<VMTemplateZoneVO> tmpltZoneSearch = _templateZoneDao.createSearchBuilder();
    tmpltZoneSearch.and("removed", tmpltZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
    tmpltZoneSearch.and("zoneId", tmpltZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);

    TmpltsInZoneSearch = createSearchBuilder();
    TmpltsInZoneSearch.and(
        "removed", TmpltsInZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
    TmpltsInZoneSearch.and()
        .op("avoidtype", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NEQ);
    TmpltsInZoneSearch.or(
        "templateType", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NULL);
    TmpltsInZoneSearch.cp();
    TmpltsInZoneSearch.join(
        "tmpltzone",
        tmpltZoneSearch,
        tmpltZoneSearch.entity().getTemplateId(),
        TmpltsInZoneSearch.entity().getId(),
        JoinBuilder.JoinType.INNER);
    tmpltZoneSearch.done();
    TmpltsInZoneSearch.done();

    CountTemplatesByAccount = createSearchBuilder(Long.class);
    CountTemplatesByAccount.select(null, Func.COUNT, null);
    CountTemplatesByAccount.and(
        "account", CountTemplatesByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
    CountTemplatesByAccount.and(
        "removed", CountTemplatesByAccount.entity().getRemoved(), SearchCriteria.Op.NULL);
    CountTemplatesByAccount.done();

    return result;
  }