/** * Generates a ComputeState query based on the tag links defined in the elastic placement zone * and the configuration of the underlying resource pool. * * The query includes computes matched by tags and computes explicitly assigned to the RP: * is of type ComputeState AND * (compute RP * ? (match endpoint AND compute type in VM_HOST, ZONE) * : (compute type is VM_GUEST)) AND * (match-tags OR explicitly-assigned) AND * tenant links matches RP tenant links */ private static Query generateRpQuery(ElasticPlacementZoneState epz, ResourcePoolState rp) { Query.Builder tagQueryBuilder = Query.Builder.create(); for (String tagLink : epz.tagLinksToMatch) { // all tagLinksToMatch must be set on the compute tagQueryBuilder.addCollectionItemClause(ResourceState.FIELD_NAME_TAG_LINKS, tagLink); } Query kindClause = Query.Builder.create().addKindFieldClause(ComputeState.class).build(); Query assignmentClause = Query.Builder.create() .addClause(tagQueryBuilder.build().setOccurance(Occurance.SHOULD_OCCUR)) .addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, epz.resourcePoolLink, Occurance.SHOULD_OCCUR) .build(); Query tenantClause = QueryUtil.addTenantClause(rp.tenantLinks); Query epzQuery = Query.Builder.create() .addClauses(kindClause, assignmentClause, tenantClause) .build(); return epzQuery; }
private void queryComputesToAssign(EpzComputeEnumerationTaskState state) { Query mustBeIn = Utils.clone(state.resourcePoolQuery); Query areOut = Query.Builder.create() .addKindFieldClause(ComputeState.class) .addFieldClause( QuerySpecification.buildCompositeFieldName( ResourceState.FIELD_NAME_CUSTOM_PROPERTIES, EPZ_CUSTOM_PROP_NAME_PREFIX + extractRpId(state)), EPZ_CUSTOM_PROP_VALUE, MatchType.TERM, Occurance.MUST_NOT_OCCUR) .build(); Query combinedQuery = Query.Builder.create().addClauses(mustBeIn, areOut).build(); queryComputes(state, combinedQuery, EpzComputeEnumerationTaskState.SubStage.ASSIGN_COMPUTES, EpzComputeEnumerationTaskState.SubStage.COMPLETED); }
private void queryComputesToUnassign(EpzComputeEnumerationTaskState state) { Query mustBeOut = Utils.clone(state.resourcePoolQuery) .setOccurance(Occurance.MUST_NOT_OCCUR); Query areIn = Query.Builder.create() .addKindFieldClause(ComputeState.class) .addCompositeFieldClause(ResourceState.FIELD_NAME_CUSTOM_PROPERTIES, EPZ_CUSTOM_PROP_NAME_PREFIX + extractRpId(state), EPZ_CUSTOM_PROP_VALUE) .build(); Query combinedQuery = Query.Builder.create().addClauses(mustBeOut, areIn).build(); queryComputes(state, combinedQuery, EpzComputeEnumerationTaskState.SubStage.UNASSIGN_COMPUTES, EpzComputeEnumerationTaskState.SubStage.QUERY_COMPUTES_TO_ASSIGN); }