Example usage for java.util List containsAll

List of usage examples for java.util List containsAll

Introduction

In this page you can find the example usage for java.util List containsAll.

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

Returns true if this list contains all of the elements of the specified collection.

Usage

From source file:com.mbv.web.rest.controller.DeliveryController.java

@RequestMapping(value = "/checkDelivery", method = RequestMethod.POST)
@ResponseBody/*from  w  w  w . j a v  a  2  s . com*/
public String checkDelivery(HttpServletRequest request, HttpServletResponse response,
        @RequestBody DeliveryParamBean delivery) throws MbvException {
    boolean flag = true;
    String message = "";
    Long degId = delivery.getDegId();
    List<DeliveryGoodBean> delGoodList = delivery.getDelGoodList();
    DeliveryBean deliveryEntity = deliveryService.getDeliveryBeanById(degId);
    if (deliveryEntity != null) {
        String province = deliveryEntity.getProvince();
        String city = deliveryEntity.getCity();
        String district = deliveryEntity.getDistrict();
        String address = deliveryEntity.getDelivAddress();
        deliveryEntity.setDelivAddress(province + city + district + address);
    }

    //??
    if (deliveryEntity != null && "8".equals(deliveryEntity.getDocState())) {
        message = "?";

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("message", message);
        returnSuccess(response, map);
        return null;
    }

    //??
    if (deliveryEntity != null && !"1".equals(deliveryEntity.getDocState())) {
        message = "???";

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("message", message);
        returnSuccess(response, map);
        return null;
    }

    List<GoodBean> goodList = deliveryService.queryGoodByParams(degId);
    //??????
    if (delGoodList != null && goodList != null && delGoodList.size() == goodList.size()) {
        List<DeliveryGoodBean> newDelGoodList = new ArrayList<DeliveryGoodBean>();
        for (GoodBean good : goodList) {
            DeliveryGoodBean delGood = new DeliveryGoodBean();
            delGood.setProdNum(good.getProdNum());
            delGood.setQty(good.getQty());
            //flag  = delGoodList.contains(delGood);
            newDelGoodList.add(delGood);
        }
        flag = (delGoodList.containsAll(newDelGoodList) && newDelGoodList.containsAll(delGoodList));
        if (!flag)
            message = "???";
    } else {
        flag = false;
        message = "???";
    }
    //????
    //flag = deliveryService.isChangeGoodInfo(deliveryEntity.getDocCode());
    if (!flag) {
        message = "???";
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("message", message);
        map.put("goodList", goodList);
        returnSuccess(response, map);
        return null;
    }

    //???
    flag = deliveryService.isChangeReceiveAddress(deliveryEntity.getDocCode());
    if (flag) {
        message = "??";
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("message", message);
        map.put("delivery", deliveryEntity);
        returnSuccess(response, map);
        return null;
    }

    message = "success";
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("message", message);
    returnSuccess(response, map);

    return null;
}

From source file:org.finra.dm.dao.DmDaoTest.java

@Test
public void testGetBusinessObjectDataEntitiesByKey() {
    // Execute the same set of tests on the sets of business object data entities with and without subpartition values.
    for (List<String> subPartitionValues : Arrays.asList(SUBPARTITION_VALUES, NO_SUBPARTITION_VALUES)) {
        // Create two business object data entities that differ on both format version and data version.
        List<BusinessObjectDataEntity> businessObjectDataEntities = Arrays.asList(
                createBusinessObjectDataEntity(NAMESPACE_CD, BOD_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE,
                        INITIAL_FORMAT_VERSION, PARTITION_VALUE, subPartitionValues, SECOND_DATA_VERSION, false,
                        BDATA_STATUS),/*from w w  w  .java2 s. c  o m*/
                createBusinessObjectDataEntity(NAMESPACE_CD, BOD_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE,
                        SECOND_FORMAT_VERSION, PARTITION_VALUE, subPartitionValues, THIRD_DATA_VERSION, false,
                        BDATA_STATUS));

        // Retrieve the first business object data entity by specifying the entire business object data key.
        List<BusinessObjectDataEntity> resultBusinessObjectDataEntities = dmDao.getBusinessObjectDataEntities(
                new BusinessObjectDataKey(NAMESPACE_CD, BOD_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE,
                        INITIAL_FORMAT_VERSION, PARTITION_VALUE, subPartitionValues, SECOND_DATA_VERSION));

        // Validate the results.
        assertNotNull(resultBusinessObjectDataEntities);
        assertEquals(1, resultBusinessObjectDataEntities.size());
        assertEquals(businessObjectDataEntities.get(0).getId(),
                resultBusinessObjectDataEntities.get(0).getId());

        // Retrieve both business object data entities by not specifying both format and data versions.
        resultBusinessObjectDataEntities = dmDao.getBusinessObjectDataEntities(
                new BusinessObjectDataKey(NAMESPACE_CD, BOD_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE,
                        null, PARTITION_VALUE, subPartitionValues, null));

        // Validate the results.
        assertNotNull(resultBusinessObjectDataEntities);
        assertTrue(resultBusinessObjectDataEntities.containsAll(businessObjectDataEntities));
        assertTrue(businessObjectDataEntities.containsAll(resultBusinessObjectDataEntities));
    }
}

From source file:com.dell.asm.asmcore.asmmanager.util.ServiceTemplateValidator.java

/**
 * Validate server network configuration
 * @param component/* w  w w  .ja v a  2  s .  c  o  m*/
 */
public void validateNetworks(ServiceTemplateComponent component, final Map<String, String> repoToTaskMap) {
    // for use with partition mask
    int M_PXE = 0x0000001;
    int M_HMGMT = 0x0000010;
    int M_HMGRN = 0x0000100;
    int M_HCLST = 0x0001000;
    int M_ISCSI = 0x0010000;
    int M_FILE = 0x0100000;
    int M_OTHER = 0x1000000;

    ServiceTemplateSetting networking = component
            .getTemplateSetting(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_NETWORK_CONFIG_ID);
    if (networking == null) {
        // some server components may not include networking configuration
        return;
    }

    // Skip network validation of hardware only configuration
    if (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_COMPID_HW.equals(component.getComponentID())) {
        return;
    }

    com.dell.asm.asmcore.asmmanager.client.networkconfiguration.NetworkConfiguration networkConfig = getServiceTemplateUtil()
            .deserializeNetwork(networking.getValue());

    if (networkConfig == null) {
        LOGGER.warn("No networking configuration on server component: " + component.getAsmGUID());
        return;
    }
    boolean isSanBoot = component.hasSanBoot();
    boolean isNoneBoot = component.hasNoneBoot();
    boolean hasESX = component.hasESX(repoToTaskMap);
    boolean hasHyperV = component.hasHyperV();
    boolean hasBareMetalOS = component.hasBareMetal(repoToTaskMap);
    boolean isISCSIBoot = component.hasSanISCSIBoot();

    List<String> vMotionNetworks = new ArrayList<String>();
    List<String> pxeNetworks = new ArrayList<String>();
    List<String> hypManangementNetworks = new ArrayList<String>();
    List<String> vsanNetworks = new ArrayList<String>();
    List<String> fipsNetworks = new ArrayList<String>();

    boolean hasPXE = false;
    boolean hasStaticPXE = false;
    boolean hasPXEOnPartNot1 = false;
    boolean hasHypervisorMgmt = false;
    boolean hasHMOnPart1 = false;
    boolean hasHypervisorMigration = false;
    boolean hasHypervisorCluster = false;
    boolean hasISCSI = false;

    boolean hasHypervisorMgmtStatic = false;
    boolean hasHypervisorMigrationStatic = false;
    boolean hasHypervisorClusterStatic = false;
    boolean hasISCSIStatic = false;
    boolean hasInvalidPartitionNetwork = false;

    boolean hasOtherStatic = false;

    boolean componentInvalidForEsx = false;
    String errorCase = null;

    List<Interface> interfaces = networkConfig.getUsedInterfaces();

    HashSet<String> partitionNetworkTypes = new HashSet<String>();
    List<List<String>> workloadNetworksCheck = new ArrayList<List<String>>();
    List<String> bareMetalOsNetworkCheck = new ArrayList<String>();

    boolean iscsiOnPort1 = false;
    boolean foundSingleISCSIOnPort1 = false;

    boolean isBootDeviceFc = false;
    boolean fcNetworkPresent = false;

    final ServiceTemplateValid componentValid = component.getComponentValid();

    for (ServiceTemplateCategory category : safeList(component.getResources())) {
        for (ServiceTemplateSetting setting : safeList(category.getParameters())) {
            if ((setting.getId()
                    .equalsIgnoreCase(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_ID)
                    && setting.getValue()
                            .equals(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_FC))) {
                isBootDeviceFc = true;
            }
            if (((setting.getId()
                    .equalsIgnoreCase(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_NETWORK_CONFIG_ID)
                    && setting.getValue().toLowerCase().contains("\"usedforfc\":true")))
                    || ((setting.getId().equalsIgnoreCase(
                            ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_NETWORK_CONFIG_ID)
                            && setting.getValue().toLowerCase().contains("\"fabrictype\":\"fc\"")))) {
                fcNetworkPresent = true;
            }
        }
    }

    if (isBootDeviceFc && !fcNetworkPresent) {
        LOGGER.error("fcNetworksError");
        componentValid.addMessage(AsmManagerMessages.fcNwtworksValidation());
        componentValid.setValid(Boolean.FALSE);
    }

    for (Interface interfaceObject : interfaces) {

        if (interfaceObject.isPartitioned() && hasHyperV) {
            // stop vaidation here and return
            componentValid.addMessage(AsmManagerMessages.serverWithHyperVPartitioned());
            componentValid.setValid(Boolean.FALSE);
            return;
        }

        List<Partition> partitions = interfaceObject.getPartitions();

        for (Partition partition : partitions) {

            partitionNetworkTypes.clear();
            bareMetalOsNetworkCheck.clear();

            List<String> networkIds = partition.getNetworks();
            Integer curMask = 0;

            if (networkIds != null) {
                for (String networkId : networkIds) {

                    Network networkObject = getNetworkService().getNetwork(networkId);

                    // In general networkObject should never be null, but ran into cases with
                    // invalid default templates where it was.
                    String networkType = networkObject == null ? "" : networkObject.getType().value();

                    boolean isStatic = networkObject != null && networkObject.isStatic();
                    if (networkType.equals(NetworkType.STORAGE_ISCSI_SAN.value())) {
                        hasISCSI = true;
                        curMask |= M_ISCSI;
                        hasISCSIStatic = isStatic;

                        if (isSanBoot && !isStatic) {
                            // iSCSI must be static fo SAN boot iSCSI
                            componentValid.addMessage(AsmManagerMessages.iscsiMustHaveStatic());
                        }
                    } else if (networkType.equals(NetworkType.PXE.value())) {
                        hasPXE = true;
                        curMask |= M_PXE;
                        if (networkObject.isStatic()) {
                            hasStaticPXE = true;
                        }
                        if (!partition.getName().equals("1"))
                            hasPXEOnPartNot1 = true;

                    } else if (networkType.equals(NetworkType.HYPERVISOR_MANAGEMENT.value())) {
                        hasHypervisorMgmt = true;
                        curMask |= M_HMGMT;
                        if (partition.getName().equals("1"))
                            hasHMOnPart1 = true;

                        hasHypervisorMgmtStatic = isStatic;

                    } else if (networkType.equals(NetworkType.HYPERVISOR_CLUSTER_PRIVATE.value())) {
                        hasHypervisorCluster = true;
                        hasHypervisorClusterStatic = isStatic;
                        curMask |= M_HCLST;
                    } else if (networkType.equals(NetworkType.HYPERVISOR_MIGRATION.value())) {
                        hasHypervisorMigration = true;
                        hasHypervisorMigrationStatic = isStatic;
                        curMask |= M_HMGRN;
                    } else if (networkType.equals(NetworkType.FILESHARE.value())) {
                        curMask |= M_FILE;
                    } else {
                        curMask |= M_OTHER;

                        if (isStatic) {
                            hasOtherStatic = true;
                        }
                    }

                    if (hasESX) {
                        if (networkType.equals(NetworkType.HYPERVISOR_MIGRATION.value())) {
                            vMotionNetworks.add(networkId);
                        }

                        if (networkType.equals(NetworkType.PXE.value())) {
                            pxeNetworks.add(networkId);
                        }

                        if (networkType.equals(NetworkType.VSAN.value())) {
                            vsanNetworks.add(networkId);
                        }

                        if (networkType.equals(NetworkType.FIP_SNOOPING.value())) {
                            fipsNetworks.add(networkId);
                        }

                        if (networkType.equals(NetworkType.HYPERVISOR_MANAGEMENT.value())) {
                            hypManangementNetworks.add(networkId);
                        }

                        if (networkType.equals(NetworkType.PRIVATE_LAN.value())
                                || networkType.equals(NetworkType.PUBLIC_LAN.value())) {
                            List<String> netTemp = new ArrayList<String>();
                            for (String netId : networkIds) {
                                if (NetworkType.PRIVATE_LAN
                                        .equals(getNetworkService().getNetwork(netId).getType())
                                        || NetworkType.PUBLIC_LAN
                                                .equals(getNetworkService().getNetwork(netId).getType())) {
                                    netTemp.add(netId);
                                }
                            }
                            workloadNetworksCheck.add(netTemp);
                        }
                        partitionNetworkTypes.add(networkType);
                    }

                    if (hasBareMetalOS) {
                        if (!hasInvalidPartitionNetwork) {
                            // partition index, number, etc. is always 0; use the name to identify the partition index
                            if (component.hasLinuxOS() && !partition.getName().equals("1")) {
                                hasInvalidPartitionNetwork = true;
                                componentValid.addMessage(
                                        AsmManagerMessages.invalidPartitionForNetwork(component.getName()));
                            }
                        }
                        bareMetalOsNetworkCheck.add(networkType);
                    }
                }
            }

            if (hasBareMetalOS && bareMetalOsNetworkCheck.size() != 0) {
                boolean validNets = true;
                for (String netType : bareMetalOsNetworkCheck) {
                    if (!netType.equals(NetworkType.PXE.value())
                            && !netType.equals(NetworkType.PRIVATE_LAN.value())
                            && !netType.equals(NetworkType.PUBLIC_LAN.value())
                            && !netType.equals(NetworkType.STORAGE_FCOE_SAN.value())
                            && !netType.equals(NetworkType.FIP_SNOOPING.value())
                            && !netType.equals(NetworkType.FILESHARE.value())
                            && !netType.equals(NetworkType.STORAGE_ISCSI_SAN.value())) {
                        validNets = false;
                        LOGGER.error("incorrectNetworksOnBareMetalOs");
                        componentValid
                                .addMessage(AsmManagerMessages.incorrectNetworkConfForBareMetalAndLinux2());
                        break;
                    }
                }
                if (!validNets)
                    break;
            }

            if (hasESX) {
                if (partitionNetworkTypes.contains(NetworkType.FIP_SNOOPING.value())
                        && !(partitionNetworkTypes.contains(NetworkType.FIP_SNOOPING.value())
                                && partitionNetworkTypes.contains(NetworkType.STORAGE_FCOE_SAN.value()))) {
                    componentInvalidForEsx = true;
                    errorCase = ERROR_DUPLICATE_NETWORK_TYPE;
                    LOGGER.error(
                            "networkTypeDuplicateOnSamePartition - FIP Snooping FCOE Networks Partitions Error");
                }
            }

            // checks per port
            // Bare metal OS
            if (hasBareMetalOS) {
                if (interfaceObject.getName().equals("Port 1")) {

                    //  In the case of boot from iSCSI, iSCSI network must be selected for one of the NIC port1. And no other network can be seleced on the same port.
                    if (isISCSIBoot && hasISCSI) {
                        iscsiOnPort1 = true;
                    }

                    if (isISCSIBoot && hasISCSI && curMask == M_ISCSI) {
                        foundSingleISCSIOnPort1 = true;
                    }
                }
            }

            // ignore all but first partitions
            if (!interfaceObject.isPartitioned())
                break;
            // Different nic types have different number of partitions but data may include more that should be ignored
            if (partition.getName().equals(Integer.toString(interfaceObject.getMaxPartitions()))) {
                break;
            }

        }
    }

    if (hasBareMetalOS) {
        //  In the case of boot from iSCSI, iSCSI network must be selected for one of the NIC port1. And no other network can be seleced on the same port.
        if (isISCSIBoot && !iscsiOnPort1) {
            componentValid.addMessage(AsmManagerMessages.iscsiMustBeOnPort1());
        }
        if (isISCSIBoot && hasISCSI && !foundSingleISCSIOnPort1) {
            componentValid.addMessage(AsmManagerMessages.iscsiMustBeTheOnlyNetwork());
        }
    }

    // For any cases that requires ASM to deploy OS, need to make sure PXE network is selected.
    // this is required for full server component
    if (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_COMPID_ALL.equals(component.getComponentID())) {
        if (!isSanBoot && !isNoneBoot && !hasPXE) {
            componentValid.addMessage(AsmManagerMessages.serverMustHavePXE());
        } else {
            // Installing Hyper-V or Windows using a static OS Installation network is not currently supported
            if (hasStaticPXE) {
                ServiceTemplateSetting osVersion = component.getParameter(
                        ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_RESOURCE,
                        ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_VERSION_ID);
            }

            if (hasBareMetalOS) {
                if (hasPXE && hasPXEOnPartNot1)
                    componentValid.addMessage(AsmManagerMessages.wrongPartition(NetworkType.PXE.value(), 1));
            }

            // In the case for Hyper-v, make sure required networks are selected.
            // Hypervisor Mgmt, Hypervisor Migration, Hypervisor Cluster private, PXE, iSCSI
            // no partitions
            if (hasHyperV) {
                if (!hasPXE)
                    componentValid.addMessage(
                            AsmManagerMessages.serverMissedNetwork("Hyper-V", NetworkType.PXE.value()));
                else if (hasPXE && hasPXEOnPartNot1)
                    componentValid.addMessage(AsmManagerMessages.wrongPartition(NetworkType.PXE.value(), 1));
                else if (!hasHypervisorMgmt)
                    componentValid.addMessage(AsmManagerMessages.serverMissedNetwork("Hyper-V",
                            NetworkType.HYPERVISOR_MANAGEMENT.value()));
                else if (hasHypervisorMgmt && !hasHMOnPart1)
                    componentValid.addMessage(
                            AsmManagerMessages.wrongPartition(NetworkType.HYPERVISOR_MANAGEMENT.value(), 1));
                else if (!hasHypervisorMigration)
                    componentValid.addMessage(AsmManagerMessages.serverMissedNetwork("Hyper-V",
                            NetworkType.HYPERVISOR_MIGRATION.value()));
                else if (!hasHypervisorCluster)
                    componentValid.addMessage(AsmManagerMessages.serverMissedNetwork("Hyper-V",
                            NetworkType.HYPERVISOR_CLUSTER_PRIVATE.value()));

                if (hasISCSI && !hasISCSIStatic) {
                    componentValid.addMessage(
                            AsmManagerMessages.hypervRequiresStatic(NetworkType.STORAGE_ISCSI_SAN.value()));
                } else if (!hasHypervisorMgmtStatic) {
                    componentValid.addMessage(
                            AsmManagerMessages.hypervRequiresStatic(NetworkType.HYPERVISOR_MANAGEMENT.value()));
                } else if (!hasHypervisorMigrationStatic) {
                    componentValid.addMessage(
                            AsmManagerMessages.hypervRequiresStatic(NetworkType.HYPERVISOR_MIGRATION.value()));
                } else if (!hasHypervisorClusterStatic) {
                    componentValid.addMessage(AsmManagerMessages
                            .hypervRequiresStatic(NetworkType.HYPERVISOR_CLUSTER_PRIVATE.value()));
                }
            }

            // In the case for ESXi, make sure required networks are selected.
            // Hypervisor Mgmt, Hypervisor Migration, Hypervisor Cluster private, PXE must be partition 1
            if (hasESX) {

                HashSet<String> duplicateNetworkCheck;

                if (!hasPXE)
                    componentValid
                            .addMessage(AsmManagerMessages.serverMissedNetwork("ESX", NetworkType.PXE.value()));
                else if (hasPXE && hasPXEOnPartNot1)
                    componentValid.addMessage(AsmManagerMessages.wrongPartition(NetworkType.PXE.value(), 1));
                else if (!hasHypervisorMgmt)
                    componentValid.addMessage(AsmManagerMessages.serverMissedNetwork("ESX",
                            NetworkType.HYPERVISOR_MANAGEMENT.value()));

                if (workloadNetworksCheck.size() > 1) {
                    for (List<String> partitionNetworks : workloadNetworksCheck) {
                        if (!(partitionNetworks.containsAll(workloadNetworksCheck.get(1))
                                && workloadNetworksCheck.get(1).containsAll(partitionNetworks))) {
                            componentInvalidForEsx = true;
                            errorCase = ERROR_WORKLOAD_NETS_NOT_SAME;
                            LOGGER.error(ERROR_WORKLOAD_NETS_NOT_SAME);
                        }
                    }
                }

                duplicateNetworkCheck = new HashSet<>(pxeNetworks);
                if (duplicateNetworkCheck.size() > 1) {
                    componentInvalidForEsx = true;
                    errorCase = ERROR_DUPLICATE_NETWORKS;
                    LOGGER.error("duplicateNetworkCheck - PXE");
                }

                duplicateNetworkCheck = new HashSet<>(vMotionNetworks);
                if (duplicateNetworkCheck.size() > 1) {
                    componentInvalidForEsx = true;
                    errorCase = ERROR_DUPLICATE_NETWORKS;
                    LOGGER.error("duplicateNetworkCheck - vMotionNetworks");
                }

                duplicateNetworkCheck = new HashSet<>(hypManangementNetworks);
                if (duplicateNetworkCheck.size() > 1) {
                    componentInvalidForEsx = true;
                    errorCase = ERROR_DUPLICATE_NETWORKS;
                    LOGGER.error("duplicateNetworkCheck - hypManangementNetworks");
                }

                duplicateNetworkCheck = new HashSet<>(fipsNetworks);
                if (duplicateNetworkCheck.size() > 1) {
                    componentInvalidForEsx = true;
                    errorCase = ERROR_DUPLICATE_NETWORKS;
                    LOGGER.error("duplicateNetworkCheck - fipsNetworks");
                }

                if (componentInvalidForEsx) {
                    if (ERROR_DUPLICATE_NETWORKS.equals(errorCase))
                        componentValid.addMessage(AsmManagerMessages.networksDuplicate());

                    if (ERROR_DUPLICATE_NETWORK_TYPE.equals(errorCase))
                        componentValid.addMessage(AsmManagerMessages.networkTypeDuplicate());

                    if (ERROR_WORKLOAD_NETS_NOT_SAME.equals(errorCase))
                        componentValid.addMessage(AsmManagerMessages.workloadNetworksNotSame());
                }
            }
        }
    }

    if (CollectionUtils.isNotEmpty(componentValid.getMessages())) {
        componentValid.setValid(Boolean.FALSE);
    }
}

From source file:org.apache.giraph.graph.BspServiceMaster.java

/**
 * Wait for a set of workers to signal that they are done with the
 * barrier./* w  ww .j a v a 2 s.c  o  m*/
 *
 * @param finishedWorkerPath Path to where the workers will register their
 *        hostname and id
 * @param workerInfoList List of the workers to wait for
 * @param event Event to wait on for a chance to be done.
 * @return True if barrier was successful, false if there was a worker
 *         failure
 */
private boolean barrierOnWorkerList(String finishedWorkerPath, List<WorkerInfo> workerInfoList,
        BspEvent event) {
    try {
        getZkExt().createOnceExt(finishedWorkerPath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, true);
    } catch (KeeperException e) {
        throw new IllegalStateException(
                "barrierOnWorkerList: KeeperException - Couldn't create " + finishedWorkerPath, e);
    } catch (InterruptedException e) {
        throw new IllegalStateException(
                "barrierOnWorkerList: InterruptedException - Couldn't create " + finishedWorkerPath, e);
    }
    List<String> hostnameIdList = new ArrayList<String>(workerInfoList.size());
    for (WorkerInfo workerInfo : workerInfoList) {
        hostnameIdList.add(workerInfo.getHostnameId());
    }
    String workerInfoHealthyPath = getWorkerInfoHealthyPath(getApplicationAttempt(), getSuperstep());
    List<String> finishedHostnameIdList;
    long nextInfoMillis = System.currentTimeMillis();
    while (true) {
        try {
            finishedHostnameIdList = getZkExt().getChildrenExt(finishedWorkerPath, true, false, false);
        } catch (KeeperException e) {
            throw new IllegalStateException("barrierOnWorkerList: KeeperException - Couldn't get "
                    + "children of " + finishedWorkerPath, e);
        } catch (InterruptedException e) {
            throw new IllegalStateException("barrierOnWorkerList: IllegalException - Couldn't get "
                    + "children of " + finishedWorkerPath, e);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("barrierOnWorkerList: Got finished worker list = " + finishedHostnameIdList + ", size = "
                    + finishedHostnameIdList.size() + ", worker list = " + workerInfoList + ", size = "
                    + workerInfoList.size() + " from " + finishedWorkerPath);
        }

        if (LOG.isInfoEnabled() && (System.currentTimeMillis() > nextInfoMillis)) {
            nextInfoMillis = System.currentTimeMillis() + 30000;
            LOG.info("barrierOnWorkerList: " + finishedHostnameIdList.size() + " out of "
                    + workerInfoList.size() + " workers finished on superstep " + getSuperstep() + " on path "
                    + finishedWorkerPath);
        }
        getContext().setStatus(getGraphMapper().getMapFunctions() + " - " + finishedHostnameIdList.size()
                + " finished out of " + workerInfoList.size() + " on superstep " + getSuperstep());
        if (finishedHostnameIdList.containsAll(hostnameIdList)) {
            break;
        }

        // Wait for a signal or no more than 60 seconds to progress
        // or else will continue.
        event.waitMsecs(60 * 1000);
        event.reset();
        getContext().progress();

        // Did a worker die?
        try {
            if ((getSuperstep() > 0) && !superstepChosenWorkerAlive(workerInfoHealthyPath, workerInfoList)) {
                return false;
            }
        } catch (KeeperException e) {
            throw new IllegalStateException(
                    "barrierOnWorkerList: KeeperException - " + "Couldn't get " + workerInfoHealthyPath, e);
        } catch (InterruptedException e) {
            throw new IllegalStateException(
                    "barrierOnWorkerList: InterruptedException - " + "Couldn't get " + workerInfoHealthyPath,
                    e);
        }
    }

    return true;
}

From source file:org.talend.repository.imports.ImportItemUtil.java

@SuppressWarnings("unchecked")
private boolean checkMigrationTasks(Project project, ItemRecord itemRecord, Project currentProject) {
    List<String> itemMigrationTasks = new ArrayList<String>(project.getMigrationTasks());
    List<String> projectMigrationTasks = new ArrayList<String>(currentProject.getMigrationTasks());

    itemMigrationTasks.removeAll(getOptionnalMigrationTasks());

    // check version + revision
    // String oldProjectVersion = project.getProductVersion();
    // String currentProjectVersion = currentProject.getProductVersion();
    // boolean currentVersionIsValid = isVersionValid(currentProjectVersion);
    // boolean oldVersionIsValid = isVersionValid(oldProjectVersion);
    // if (currentVersionIsValid && oldVersionIsValid) {
    // boolean canImport = canContinueImport(oldProjectVersion, currentProjectVersion);
    // if (!canImport) {
    // String message = "The version of " + project.getLabel() + " should be lower than the current project.";
    // itemRecord.addError(message);
    // log.info(message);
    ///*  w ww . ja  v a2s. c  om*/
    // return false;
    // }
    // }

    // Talend Platform Big Data edition-5.0.2.r78327 / Talend Open Studio for Data Integration-5.1.0NB.r80928

    // the 2 are valid versions SO

    // 1. Check if all the migration tasks of the items are done in the
    // project:
    // if not, the item use a more recent version of TOS: impossible to
    // import (forward compatibility)
    // if no correct version and revision found in the productVersion, do same as before
    if (!projectMigrationTasks.containsAll(itemMigrationTasks)) {
        itemMigrationTasks.removeAll(projectMigrationTasks);

        String message = Messages.getString("ImportItemUtil.message", itemRecord.getItemName(), //$NON-NLS-1$
                itemMigrationTasks);
        itemRecord.addError(message);
        log.info(message);

        return false;
    }
    // force to redo this migration task, even if already did before.
    itemMigrationTasks.remove("org.talend.repository.model.migration.AutoUpdateRelationsMigrationTask");

    // 2. Get all the migration tasks to apply on this item on import
    // (backwards compatibility)
    // (those that are in the project but not in the item)
    projectMigrationTasks.removeAll(itemMigrationTasks);
    itemRecord.setMigrationTasksToApply(projectMigrationTasks);

    return true;
}

From source file:com.vmware.bdd.manager.ClusterManager.java

@ClusterManagerPointcut
@Transactional/*from  www  .  j ava 2  s  . c o  m*/
public void updateCluster(ClusterCreate clusterUpdate, boolean ignoreWarning, boolean appendResource)
        throws Exception {
    String clusterName = clusterUpdate.getName();
    ClusterEntity cluster = clusterEntityMgr.findByName(clusterName);
    if (cluster == null) {
        logger.error("cluster " + clusterName + " does not exist");
        throw BddException.NOT_FOUND("Cluster", clusterName);
    }
    ValidationUtils.validateVersion(clusterEntityMgr, clusterName);

    List<String> newRpList = clusterUpdate.getRpNames();

    if (!CollectionUtils.isEmpty(newRpList)) {
        //Check whether the new resourcepools are valid in vc_resource_pool
        List<String> existRPs = validateGivenRp(newRpList);
        if (CollectionUtils.isEmpty(existRPs)) {
            throw ClusterConfigException.NO_RESOURCE_POOL_ADDED();
        }
        //check whether the updating resourcepool only the new ones
        if (appendResource == true) {
            List<String> usingRpList = cluster.getVcRpNameList();
            if (CollectionUtils.isEmpty(usingRpList)) {
                return;
            }
            newRpList = appendResource(usingRpList, newRpList);
        } else {
            //Check whether the new resourcepools include the current resourcepools which are used by this cluster
            Set<VcResourcePoolEntity> usedVCRps = cluster.getUsedRps();
            List<String> usedRpList = new ArrayList<String>(usedVCRps.size());
            for (VcResourcePoolEntity rp : usedVCRps) {
                usedRpList.add(rp.getName());
            }
            logger.info("Updating resourcepools for cluster " + clusterName + " from " + usedRpList.toString()
                    + " to " + newRpList.toString());
            if (!newRpList.containsAll(usedRpList)) {
                throw BddException.NEW_RP_EXCLUDE_OLD_RP(null, usedRpList.toString(), newRpList.toString());
            }
        }

        cluster.setVcRpNameList(newRpList);
    }

    List<String> newDsList = clusterUpdate.getDsNames();

    if (!CollectionUtils.isEmpty(newDsList)) {
        //Check whether the new datastores are valid vc_data_store
        if (CollectionUtils.isEmpty(validateGivenDS(newDsList))) {
            throw ClusterConfigException.NO_DATASTORE_ADDED();
        }
        //check whether the updating resourcepool only the new ones
        if (appendResource == true) {
            List<String> usingDsList = cluster.getVcDatastoreNameList();
            if (CollectionUtils.isEmpty(usingDsList))
                return;
            newDsList = appendResource(usingDsList, newDsList);
        }
        //Check whether the new dsNames contain all datastores used by this cluster already
        List<String> usedDsList = cluster.getVcDatastoreNameList();
        logger.info("Updating dsNames for cluster " + clusterName + " from " + usedDsList + " to "
                + newDsList.toString());
        if (!ignoreWarning) {
            if (CollectionUtils.isEmpty(usedDsList)) {
                throw WarningMessageException.SET_EMPTY_DATASTORES_TO_NON_EMTPY(null, newDsList.toString());
            } else if (!newDsList.containsAll(usedDsList)) {
                throw WarningMessageException.NEW_DATASTORES_EXCLUDE_OLD_DATASTORES(null, newDsList.toString(),
                        usedDsList.toString());
            }
        }

        cluster.setVcDatastoreNameList(newDsList);
    }

    clusterEntityMgr.update(cluster);
}

From source file:org.openecomp.sdc.be.model.operations.impl.PropertyOperation.java

private boolean isPropertyOmitted(List<PropertyDefinition> newProperties,
        List<PropertyDefinition> oldProperties, String dataTypeName) {

    boolean isValid = validateChangeInCaseOfEmptyProperties(newProperties, oldProperties, dataTypeName);
    if (false == isValid) {
        log.debug("At least one property is missing in the new data type {}", dataTypeName);
        return false;
    }/*from   w  w  w . ja va 2 s . co  m*/

    if (newProperties != null && oldProperties != null) {

        List<String> newProps = newProperties.stream().map(p -> p.getName()).collect(Collectors.toList());
        List<String> oldProps = oldProperties.stream().map(p -> p.getName()).collect(Collectors.toList());

        if (false == newProps.containsAll(oldProps)) {
            StringJoiner joiner = new StringJoiner(",", "[", "]");
            newProps.forEach(p -> joiner.add(p));
            log.debug(
                    "Properties {} in data type {} are missing, but they already defined in the existing data type",
                    joiner.toString(), dataTypeName);
            return true;
        }

    }
    return false;
}

From source file:it.unibo.alchemist.model.implementations.reactions.SAPEREReaction.java

@Override
public void execute() {
    if (possibleMatches.isEmpty()) {
        for (final ILsaAction a : getSAPEREActions()) {
            a.setExecutionContext(null, validNodes);
            a.execute();//  w w  w  .  ja  va 2  s.  c  om
        }
        return;
    }
    final Position nodePosCache = modifiesOnlyLocally ? environment.getPosition(getNode()) : null;
    final List<? extends ILsaMolecule> localContentCache = modifiesOnlyLocally
            ? new ArrayList<>(getNode().getLsaSpace())
            : null;
    Map<HashString, ITreeNode<?>> matches = null;
    Map<ILsaNode, List<ILsaMolecule>> toRemove = null;
    /*
     * If there is infinite propensity, the last match added is the one to
     * choose, since it is the one which generated the "infinity" value.
     */
    if (totalPropensity == Double.POSITIVE_INFINITY) {
        final int index = possibleMatches.size() - 1;
        matches = possibleMatches.get(index);
        toRemove = possibleRemove.get(index);
    } else if (numericRate()) {
        /*
         * If the rate is numeric, the choice is just random
         */
        final int index = Math.abs(rng.nextInt()) % possibleMatches.size();
        matches = possibleMatches.get(index);
        toRemove = possibleRemove.get(index);
    } else {
        /*
         * Otherwise, the matches must be chosen randomly using their
         * propensities
         */
        final double index = rng.nextDouble() * totalPropensity;
        double sum = 0;
        for (int i = 0; matches == null; i++) {
            sum += propensities.get(i);
            if (sum > index) {
                matches = possibleMatches.get(i);
                toRemove = possibleRemove.get(i);
            }
        }
    }
    /*
     * The matched LSAs must be removed from the local space, if no action
     * added them back.
     */
    for (final Entry<ILsaNode, List<ILsaMolecule>> entry : toRemove.entrySet()) {
        final ILsaNode n = entry.getKey();
        for (final ILsaMolecule m : entry.getValue()) {
            n.removeConcentration(m);
        }
    }
    /*
     * #T Must be loaded by the reaction, which is the only structure aware
     * of the time. Other special values (#NEIG, #O, #D) will be allocated
     * inside the actions.
     */
    matches.put(LsaMolecule.SYN_T, new NumTreeNode(getTau().toDouble()));
    for (final ILsaAction a : getSAPEREActions()) {
        a.setExecutionContext(matches, validNodes);
        a.execute();
    }

    /*
     * Empty action optimization
     */
    if (modifiesOnlyLocally) {
        final ILsaNode n = getNode();
        if (nodePosCache.equals(environment.getPosition(getNode()))) {
            final List<? extends ILsaMolecule> contents = n.getLsaSpace();
            if (contents.size() == localContentCache.size()) {
                emptyExecution = localContentCache.containsAll(contents);
            }
        }
    }
}

From source file:ubic.gemma.analysis.expression.diff.LinearModelAnalyzer.java

/**
 * Remove all configurations that have to do with factors that aren't in the selected factors.
 * /*from  w ww .  java  2 s  .  c om*/
 * @param samplesInSubset
 * @param factors the factors that will be included
 * @param config
 * @return an updated config; the baselines are cleared; subset is cleared; interactions are only kept if they only
 *         involve the given factors.
 */
private DifferentialExpressionAnalysisConfig fixConfigForSubset(List<ExperimentalFactor> factors,
        DifferentialExpressionAnalysisConfig config) {

    DifferentialExpressionAnalysisConfig newConfig = new DifferentialExpressionAnalysisConfig();
    //
    // /*
    // * Drop factors that are constant in the subset.
    // */
    // Map<ExperimentalFactor, Collection<FactorValue>> ef2FvsUsedInSubset = new HashMap<ExperimentalFactor,
    // Collection<FactorValue>> ();
    // for ( BioMaterial bm : samplesInSubset ) {
    // for ( FactorValue fv : bm.getFactorValues() ) {
    // ExperimentalFactor ef = fv.getExperimentalFactor();
    // if ( !ef2FvsUsedInSubset.containsKey( ef ) ) {
    // ef2FvsUsedInSubset.put( ef, new HashSet<FactorValue>() );
    // }
    // ef2FvsUsedInSubset.get( ef ).add( fv );
    // }
    // }
    //
    // Collection<ExperimentalFactor> efsToUse = new HashSet<ExperimentalFactor>();
    // for ( ExperimentalFactor ef : factors ) {
    // Collection<FactorValue> fvsUsed = ef2FvsUsedInSubset.get( ef );
    // if ( fvsUsed.size() > 1 ) {
    // efsToUse.add( ef );
    // }
    // }

    newConfig.setBaseLineFactorValues(null);

    if (!config.getInteractionsToInclude().isEmpty()) {
        Collection<Collection<ExperimentalFactor>> newInteractionsToInclude = new HashSet<Collection<ExperimentalFactor>>();
        for (Collection<ExperimentalFactor> interactors : config.getInteractionsToInclude()) {
            if (factors.containsAll(interactors)) {
                newInteractionsToInclude.add(interactors);
            }
        }

        newConfig.setInteractionsToInclude(newInteractionsToInclude);
    }

    newConfig.setSubsetFactor(null);
    newConfig.setFactorsToInclude(factors);
    newConfig.setQvalueThreshold(config.getQvalueThreshold());

    return newConfig;

}

From source file:org.finra.herd.dao.HerdDaoTest.java

@Test
public void testGetBusinessObjectDataEntitiesByKey() {
    // Execute the same set of tests on the sets of business object data entities with and without subpartition values.
    for (List<String> subPartitionValues : Arrays.asList(SUBPARTITION_VALUES, NO_SUBPARTITION_VALUES)) {
        // Create two business object data entities that differ on both format version and data version.
        List<BusinessObjectDataEntity> businessObjectDataEntities = Arrays.asList(
                createBusinessObjectDataEntity(NAMESPACE_CD, BOD_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE,
                        INITIAL_FORMAT_VERSION, PARTITION_VALUE, subPartitionValues, SECOND_DATA_VERSION, false,
                        BDATA_STATUS),/*w  w w  .j a  v a  2s. c o  m*/
                createBusinessObjectDataEntity(NAMESPACE_CD, BOD_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE,
                        SECOND_FORMAT_VERSION, PARTITION_VALUE, subPartitionValues, THIRD_DATA_VERSION, false,
                        BDATA_STATUS));

        // Retrieve the first business object data entity by specifying the entire business object data key.
        List<BusinessObjectDataEntity> resultBusinessObjectDataEntities = herdDao.getBusinessObjectDataEntities(
                new BusinessObjectDataKey(NAMESPACE_CD, BOD_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE,
                        INITIAL_FORMAT_VERSION, PARTITION_VALUE, subPartitionValues, SECOND_DATA_VERSION));

        // Validate the results.
        assertNotNull(resultBusinessObjectDataEntities);
        assertEquals(1, resultBusinessObjectDataEntities.size());
        assertEquals(businessObjectDataEntities.get(0).getId(),
                resultBusinessObjectDataEntities.get(0).getId());

        // Retrieve both business object data entities by not specifying both format and data versions.
        resultBusinessObjectDataEntities = herdDao.getBusinessObjectDataEntities(
                new BusinessObjectDataKey(NAMESPACE_CD, BOD_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE,
                        null, PARTITION_VALUE, subPartitionValues, null));

        // Validate the results.
        assertNotNull(resultBusinessObjectDataEntities);
        assertTrue(resultBusinessObjectDataEntities.containsAll(businessObjectDataEntities));
        assertTrue(businessObjectDataEntities.containsAll(resultBusinessObjectDataEntities));
    }
}