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 Host> findHosts(long accountId, long instanceId) {
   return create()
       .select(HOST.fields())
       .from(INSTANCE)
       .join(INSTANCE_HOST_MAP)
       .on(INSTANCE.ID.eq(INSTANCE_HOST_MAP.INSTANCE_ID))
       .join(HOST)
       .on(HOST.ID.eq(INSTANCE_HOST_MAP.HOST_ID))
       .where(
           HOST.REMOVED
               .isNull()
               .and(INSTANCE_HOST_MAP.REMOVED.isNull())
               .and(INSTANCE.ID.eq(instanceId)))
       .fetchInto(HostRecord.class);
 }
Ejemplo n.º 4
0
 @Override
 public Host getHost(Instance instance) {
   Condition cond = getInstanceHostConstraint(instance);
   try {
     return create()
         .selectDistinct(HOST.fields())
         .from(HOST)
         .join(INSTANCE_HOST_MAP)
         .on(INSTANCE_HOST_MAP.HOST_ID.eq(HOST.ID))
         .join(INSTANCE)
         .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
         .where(INSTANCE_HOST_MAP.REMOVED.isNull().and(cond))
         .fetchOneInto(HostRecord.class);
   } catch (InvalidResultException e) {
     throw new FailedToAllocate("Instances to allocate assigned to different hosts.");
   }
 }
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
  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;
  }
Ejemplo n.º 7
0
  @Override
  public Map<String, List<InstanceHostMap>> getInstanceHostMapsWithHostUuid(long instanceId) {
    Map<Record, List<InstanceHostMap>> result =
        create()
            .select(INSTANCE_HOST_MAP.fields())
            .select(HOST.UUID)
            .from(INSTANCE_HOST_MAP)
            .join(HOST)
            .on(INSTANCE_HOST_MAP.HOST_ID.eq(HOST.ID))
            .where(
                INSTANCE_HOST_MAP
                    .INSTANCE_ID
                    .eq(instanceId)
                    .and(INSTANCE_HOST_MAP.REMOVED.isNull()))
            .fetchGroups(new Field[] {HOST.UUID}, InstanceHostMap.class);

    Map<String, List<InstanceHostMap>> maps = new HashMap<>();
    for (Map.Entry<Record, List<InstanceHostMap>> entry : result.entrySet()) {
      String uuid = (String) entry.getKey().getValue(0);
      maps.put(uuid, entry.getValue());
    }
    return maps;
  }