Exemple #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;
  }
Exemple #2
0
 @Override
 public List<? extends Instance> findUnallocatedInstanceByDeploymentUnitUuid(
     long accountId, String deploymentUnitUuid) {
   return create()
       .select(INSTANCE.fields())
       .from(INSTANCE)
       .leftOuterJoin(INSTANCE_HOST_MAP)
       .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
       .where(
           INSTANCE
               .REMOVED
               .isNull()
               .and(INSTANCE_HOST_MAP.ID.isNull())
               .and(INSTANCE.DEPLOYMENT_UNIT_UUID.eq(deploymentUnitUuid))
               .and(INSTANCE.ALLOCATION_STATE.eq(CommonStatesConstants.INACTIVE)))
       .fetchInto(InstanceRecord.class);
 }
Exemple #3
0
 @Override
 public List<? extends Instance> getNonRemovedInstanceOn(Long hostId) {
   return create()
       .select(INSTANCE.fields())
       .from(INSTANCE)
       .join(INSTANCE_HOST_MAP)
       .on(INSTANCE_HOST_MAP.HOST_ID.eq(hostId).and(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID)))
       .where(
           INSTANCE
               .REMOVED
               .isNull()
               .and(
                   INSTANCE.STATE.notIn(
                       InstanceConstants.STATE_ERROR,
                       InstanceConstants.STATE_ERRORING,
                       CommonStatesConstants.REMOVING)))
       .fetchInto(InstanceRecord.class);
 }
Exemple #4
0
 @Override
 public List<? extends Instance> findBadInstances(int count) {
   return create()
       .select(INSTANCE.fields())
       .from(INSTANCE)
       .join(INSTANCE_HOST_MAP)
       .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
       .join(HOST)
       .on(INSTANCE_HOST_MAP.HOST_ID.eq(HOST.ID))
       .where(
           HOST.REMOVED
               .isNotNull()
               .and(INSTANCE.REMOVED.isNull())
               .and(
                   INSTANCE.STATE.notIn(
                       InstanceConstants.STATE_STOPPING, CommonStatesConstants.REMOVING)))
       .limit(count)
       .fetchInto(InstanceRecord.class);
 }
Exemple #5
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);
 }
Exemple #6
0
  public List<Instance> getUnmappedDeploymentUnitInstances(String deploymentUnitUuid) {
    List<? extends Instance> instanceRecords =
        create()
            .select(INSTANCE.fields())
            .from(INSTANCE)
            .leftOuterJoin(INSTANCE_HOST_MAP)
            .on(
                INSTANCE_HOST_MAP
                    .INSTANCE_ID
                    .eq(INSTANCE.ID)
                    .and(INSTANCE_HOST_MAP.REMOVED.isNull()))
            .where(INSTANCE.REMOVED.isNull())
            .and(INSTANCE.DEPLOYMENT_UNIT_UUID.eq(deploymentUnitUuid))
            .and(INSTANCE_HOST_MAP.ID.isNull())
            .fetchInto(InstanceRecord.class);

    List<Instance> instances = new ArrayList<Instance>();
    for (Instance i : instanceRecords) {
      instances.add(i);
    }
    return instances;
  }
Exemple #7
0
 @Override
 public List<? extends Instance> findInstancesFor(Service service) {
   return create()
       .select(INSTANCE.fields())
       .from(INSTANCE)
       .join(SERVICE_EXPOSE_MAP)
       .on(
           SERVICE_EXPOSE_MAP
               .INSTANCE_ID
               .eq(INSTANCE.ID)
               .and(SERVICE_EXPOSE_MAP.SERVICE_ID.eq(service.getId()))
               .and(
                   SERVICE_EXPOSE_MAP.STATE.in(
                       CommonStatesConstants.ACTIVATING,
                       CommonStatesConstants.ACTIVE,
                       CommonStatesConstants.REQUESTED))
               .and(
                   INSTANCE.STATE.notIn(
                       CommonStatesConstants.PURGING,
                       CommonStatesConstants.PURGED,
                       CommonStatesConstants.REMOVED,
                       CommonStatesConstants.REMOVING)))
       .fetchInto(InstanceRecord.class);
 }