Ejemplo n.º 1
0
 @Override
 public boolean hostHasContainerLabel(long hostId, String labelKey, String labelValue) {
   return create()
           .select(LABEL.ID)
           .from(LABEL)
           .join(INSTANCE_LABEL_MAP)
           .on(LABEL.ID.eq(INSTANCE_LABEL_MAP.LABEL_ID))
           .join(INSTANCE_HOST_MAP)
           .on(INSTANCE_LABEL_MAP.INSTANCE_ID.eq(INSTANCE_HOST_MAP.INSTANCE_ID))
           .join(INSTANCE)
           .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
           .leftOuterJoin(SERVICE_EXPOSE_MAP)
           .on(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(INSTANCE.ID))
           .where(INSTANCE_HOST_MAP.HOST_ID.eq(hostId))
           .and(LABEL.REMOVED.isNull())
           .and(INSTANCE_LABEL_MAP.REMOVED.isNull())
           .and(INSTANCE_HOST_MAP.REMOVED.isNull())
           .and(INSTANCE.REMOVED.isNull())
           .and(
               INSTANCE.STATE.notIn(
                   InstanceConstants.STATE_ERROR, InstanceConstants.STATE_ERRORING))
           .and(LABEL.KEY.equalIgnoreCase(labelKey))
           .and(LABEL.VALUE.equalIgnoreCase(labelValue))
           .and(SERVICE_EXPOSE_MAP.UPGRADE.eq(false).or(SERVICE_EXPOSE_MAP.UPGRADE.isNull()))
           .fetchInto(Long.class)
           .size()
       > 0;
 }
Ejemplo n.º 2
0
 @Override
 public List<Port> getUsedPortsForHostExcludingInstance(long hostId, long instanceId) {
   return create()
       .select(PORT.fields())
       .from(PORT)
       .join(INSTANCE_HOST_MAP)
       .on(PORT.INSTANCE_ID.eq(INSTANCE_HOST_MAP.INSTANCE_ID))
       .join(INSTANCE)
       .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
       .leftOuterJoin(SERVICE_EXPOSE_MAP)
       .on(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(INSTANCE.ID))
       .where(
           INSTANCE_HOST_MAP
               .HOST_ID
               .eq(hostId)
               .and(INSTANCE.REMOVED.isNull())
               .and(INSTANCE.ID.ne(instanceId))
               .and(
                   INSTANCE.STATE.in(
                       InstanceConstants.STATE_STARTING,
                       InstanceConstants.STATE_RESTARTING,
                       InstanceConstants.STATE_RUNNING))
               .and(INSTANCE_HOST_MAP.REMOVED.isNull())
               .and(PORT.REMOVED.isNull())
               .and(SERVICE_EXPOSE_MAP.UPGRADE.eq(false).or(SERVICE_EXPOSE_MAP.UPGRADE.isNull())))
       .fetchInto(Port.class);
 }
Ejemplo n.º 3
0
 @Override
 public List<? extends InstanceLink> findBadInstanceLinks(int count) {
   return create()
       .select(INSTANCE_LINK.fields())
       .from(INSTANCE_LINK)
       .join(INSTANCE)
       .on(INSTANCE.ID.eq(INSTANCE_LINK.TARGET_INSTANCE_ID))
       .where(INSTANCE.STATE.eq(CommonStatesConstants.PURGED))
       .limit(count)
       .fetchInto(InstanceLinkRecord.class);
 }
Ejemplo n.º 4
0
 @Override
 public List<? extends Nic> findBadNics(int count) {
   return create()
       .select(NIC.fields())
       .from(NIC)
       .join(INSTANCE)
       .on(INSTANCE.ID.eq(NIC.INSTANCE_ID))
       .where(
           NIC.REMOVED
               .isNull()
               .and(INSTANCE.STATE.eq(CommonStatesConstants.PURGED))
               .and(
                   NIC.STATE.notIn(
                       CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING)))
       .limit(count)
       .fetchInto(NicRecord.class);
 }
Ejemplo n.º 5
0
 @Override
 public List<? extends InstanceHostMap> findBadInstanceHostMaps(int count) {
   return create()
       .select(INSTANCE_HOST_MAP.fields())
       .from(INSTANCE_HOST_MAP)
       .join(INSTANCE)
       .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
       .where(
           INSTANCE_HOST_MAP
               .REMOVED
               .isNull()
               .and(INSTANCE.STATE.eq(CommonStatesConstants.PURGED))
               .and(
                   INSTANCE_HOST_MAP.STATE.notIn(
                       CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING)))
       .limit(count)
       .fetchInto(InstanceHostMapRecord.class);
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
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;
  }