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 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;
 }
Exemple #3
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);
 }
Exemple #4
0
 @Override
 public boolean isVolumeInUseOnHost(long volumeId, long hostId) {
   return create()
           .select(INSTANCE.ID)
           .from(INSTANCE)
           .join(MOUNT)
           .on(MOUNT.INSTANCE_ID.eq(INSTANCE.ID).and(MOUNT.VOLUME_ID.eq(volumeId)))
           .join(INSTANCE_HOST_MAP)
           .on(
               INSTANCE_HOST_MAP
                   .INSTANCE_ID
                   .eq(INSTANCE.ID)
                   .and(INSTANCE_HOST_MAP.HOST_ID.eq(hostId)))
           .join(HOST)
           .on(HOST.ID.eq(INSTANCE_HOST_MAP.HOST_ID))
           .where(
               INSTANCE
                   .REMOVED
                   .isNull()
                   .and(INSTANCE_HOST_MAP.STATE.notIn(IHM_STATES))
                   .and(
                       (INSTANCE
                           .HEALTH_STATE
                           .isNull()
                           .or(
                               INSTANCE.HEALTH_STATE.eq(
                                   HealthcheckConstants.HEALTH_STATE_HEALTHY)))))
           .fetch()
           .size()
       > 0;
 }
Exemple #5
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 #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);
 }
Exemple #7
0
  @Override
  public List<IpAddressToServiceIndex> getIpToIndex(Service service) {
    MultiRecordMapper<IpAddressToServiceIndex> mapper =
        new MultiRecordMapper<IpAddressToServiceIndex>() {
          @Override
          protected IpAddressToServiceIndex map(List<Object> input) {
            ServiceIndex index = (ServiceIndex) input.get(0);
            IpAddress ip = (IpAddress) input.get(1);
            Subnet subnet = (Subnet) input.get(2);
            IpAddressToServiceIndex data = new IpAddressToServiceIndex(index, ip, subnet);
            return data;
          }
        };

    ServiceIndexTable serviceIndex = mapper.add(SERVICE_INDEX);
    IpAddressTable ipAddress = mapper.add(IP_ADDRESS);
    SubnetTable subnet = mapper.add(SUBNET);
    ServiceExposeMapTable exposeMap = mapper.add(SERVICE_EXPOSE_MAP, SERVICE_EXPOSE_MAP.REMOVED);

    return create()
        .select(mapper.fields())
        .from(INSTANCE)
        .join(exposeMap)
        .on(exposeMap.INSTANCE_ID.eq(INSTANCE.ID))
        .join(NIC)
        .on(NIC.INSTANCE_ID.eq(exposeMap.INSTANCE_ID))
        .join(IP_ADDRESS_NIC_MAP)
        .on(IP_ADDRESS_NIC_MAP.NIC_ID.eq(NIC.ID))
        .join(ipAddress)
        .on(IP_ADDRESS_NIC_MAP.IP_ADDRESS_ID.eq(ipAddress.ID))
        .join(serviceIndex)
        .on(serviceIndex.ID.eq(INSTANCE.SERVICE_INDEX_ID))
        .join(subnet)
        .on(ipAddress.SUBNET_ID.eq(subnet.ID))
        .where(exposeMap.SERVICE_ID.eq(service.getId()))
        .and(exposeMap.REMOVED.isNull())
        .and(NIC.REMOVED.isNull())
        .and(ipAddress.REMOVED.isNull())
        .and(ipAddress.ADDRESS.isNotNull())
        .and(INSTANCE.REMOVED.isNull())
        .and(ipAddress.ROLE.eq(IpAddressConstants.ROLE_PRIMARY))
        .fetch()
        .map(mapper);
  }
Exemple #8
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 #9
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 #10
0
 @Override
 public List<Long> getInstancesWithVolumeMounted(long volumeId, long currentInstanceId) {
   return create()
       .select(INSTANCE.ID)
       .from(INSTANCE)
       .join(MOUNT)
       .on(MOUNT.INSTANCE_ID.eq(INSTANCE.ID).and(MOUNT.VOLUME_ID.eq(volumeId)))
       .join(INSTANCE_HOST_MAP)
       .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
       .where(
           INSTANCE
               .REMOVED
               .isNull()
               .and(INSTANCE.ID.ne(currentInstanceId))
               .and(INSTANCE_HOST_MAP.STATE.notIn(IHM_STATES))
               .and(
                   (INSTANCE
                       .HEALTH_STATE
                       .isNull()
                       .or(INSTANCE.HEALTH_STATE.eq(HealthcheckConstants.HEALTH_STATE_HEALTHY)))))
       .fetchInto(Long.class);
 }