Example #1
0
  @Override
  public List<? extends Instance> listNonRemovedInstances(Account account, boolean forService) {
    List<? extends Instance> serviceInstances =
        create()
            .select(INSTANCE.fields())
            .from(INSTANCE)
            .join(SERVICE_EXPOSE_MAP)
            .on(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(INSTANCE.ID))
            .where(INSTANCE.ACCOUNT_ID.eq(account.getId()))
            .and(INSTANCE.REMOVED.isNull())
            .fetchInto(InstanceRecord.class);
    if (forService) {
      return serviceInstances;
    }
    List<? extends Instance> allInstances =
        create()
            .select(INSTANCE.fields())
            .from(INSTANCE)
            .where(INSTANCE.ACCOUNT_ID.eq(account.getId()))
            .and(INSTANCE.REMOVED.isNull())
            .fetchInto(InstanceRecord.class);

    allInstances.removeAll(serviceInstances);
    return allInstances;
  }
Example #2
0
 @Override
 public List<? extends Instance> findInstanceByServiceName(long accountId, String serviceName) {
   return create()
       .select(INSTANCE.fields())
       .from(INSTANCE)
       .join(SERVICE_EXPOSE_MAP)
       .on(INSTANCE.ID.eq(SERVICE_EXPOSE_MAP.INSTANCE_ID))
       .join(SERVICE)
       .on(SERVICE.ID.eq(SERVICE_EXPOSE_MAP.SERVICE_ID))
       .where(
           INSTANCE
               .STATE
               .eq(InstanceConstants.STATE_RUNNING)
               .and(INSTANCE.ACCOUNT_ID.eq(accountId))
               .and(SERVICE_EXPOSE_MAP.REMOVED.isNull())
               .and(SERVICE.REMOVED.isNull())
               .and(SERVICE.NAME.eq(serviceName)))
       .fetchInto(InstanceRecord.class);
 }
Example #3
0
  @Override
  public Instance getInstanceByUuidOrExternalId(Long accountId, String uuid, String externalId) {
    Instance instance = null;
    Condition condition =
        INSTANCE
            .ACCOUNT_ID
            .eq(accountId)
            .and(INSTANCE.STATE.notIn(CommonStatesConstants.PURGED, CommonStatesConstants.PURGING));

    if (StringUtils.isNotEmpty(uuid)) {
      instance =
          create().selectFrom(INSTANCE).where(condition.and(INSTANCE.UUID.eq(uuid))).fetchAny();
    }

    if (instance == null && StringUtils.isNotEmpty(externalId)) {
      instance =
          create()
              .selectFrom(INSTANCE)
              .where(condition.and(INSTANCE.EXTERNAL_ID.eq(externalId)))
              .fetchAny();
    }

    return instance;
  }