key: clusterName + topologyId + metaType + id
487202
@Override
    public byte[] getKey() {
        StringBuilder sb = new StringBuilder(64);
        sb.append(clusterName).append(MetricUtils.AT).append(topologyId).append(MetricUtils.AT)
                .append(metaType).append(MetricUtils.AT).append(id);
        return sb.toString().getBytes();
    }
1209403
@Given("^I( securely)? connect to '(Cassandra|Mongo|Elasticsearch)' cluster at '(.+)'$")
    public void connect(String secured, String clusterType, String url) throws DBException, UnknownHostException {
        switch (clusterType) {
            case "Cassandra":
                commonspec.getCassandraClient().setHost(url);
                commonspec.getCassandraClient().connect(secured);
                break;
            case "Mongo":
                commonspec.getMongoDBClient().connect();
                break;
            case "Elasticsearch":
                LinkedHashMap<String, Object> settings_map = new LinkedHashMap<String, Object>();
                settings_map.put("cluster.name", System.getProperty("ES_CLUSTER", ES_DEFAULT_CLUSTER_NAME));
                commonspec.getElasticSearchClient().setSettings(settings_map);
                commonspec.getElasticSearchClient().connect();
                break;
            default:
                throw new DBException("Unknown cluster type");
        }
    }
590510
public static String metricName(String type, String topologyId, String componentId, int taskId, String streamId, String group, String name) {
        return concat(type, topologyId, componentId, taskId, streamId, group, name);
    }
662182
def cluster_2_json(self):
        
        LOGGER.debug("Cluster.cluster_2_json")
        json_obj = {
            'clusterID': self.id,
            'clusterName': self.name,
            'clusterContainersID': self.containers_id
        }
        return json_obj
207169
def _write_cluster(metacluster, cluster, loci, idx, path):
    
    out_file = op.join(path, 'log', str(idx) + '.bed')
    with utils.safe_run(out_file):
        with open(out_file, 'w') as out_handle:
            for idc in metacluster:
                for idl in cluster[idc].loci2seq:
                    pos = loci[idl].list()
                    print("\t".join(pos[:4] + [str(len(cluster[idc].loci2seq[idl]))] + [pos[-1]]), file=out_handle, end="")
1165550
def get_cluster_assignment(self):
        """"""
        plan = self.get_cluster_plan()
        assignment = {}
        for elem in plan['partitions']:
            assignment[
                (elem['topic'], elem['partition'])
            ] = elem['replicas']

        return assignment
584234
private static int getMapperId(long key, int numReducers, int maxKeySpace) {
    key = key - getFirstSumKey(numReducers, maxKeySpace);
    return (int) (key / numReducers);
  }
630091
private Map<Integer, LocalAssignment> getLocalAssign(StormClusterState stormClusterState, String supervisorId,
                                                         Map<String, Assignment> assignments) throws Exception {
        Map<Integer, LocalAssignment> portToAssignment = new HashMap<>();
        for (Entry<String, Assignment> assignEntry : assignments.entrySet()) {
            String topologyId = assignEntry.getKey();
            Assignment assignment = assignEntry.getValue();

            Map<Integer, LocalAssignment> portTasks = readMyTasks(stormClusterState, topologyId, supervisorId, assignment);
            if (portTasks == null) {
                continue;
            }

            // a port must be assigned to one assignment
            for (Entry<Integer, LocalAssignment> entry : portTasks.entrySet()) {
                Integer port = entry.getKey();
                LocalAssignment la = entry.getValue();
                if (!portToAssignment.containsKey(port)) {
                    portToAssignment.put(port, la);
                } else {
                    throw new RuntimeException("Should not have multiple topologies assigned to one port");
                }
            }
        }

        return portToAssignment;
    }
573277
private Map<String, String> generateSidToHost() {
        Map<String, String> sidToHostname = new HashMap<>();
        if (oldAssignment != null) {
            sidToHostname.putAll(oldAssignment.getNodeHost());
        }

        for (Entry<String, SupervisorInfo> entry : cluster.entrySet()) {
            String supervisorId = entry.getKey();
            SupervisorInfo supervisorInfo = entry.getValue();

            sidToHostname.put(supervisorId, supervisorInfo.getHostName());

        }

        return sidToHostname;
    }
841621
public TopologyMetric getTopologyMetric(String topologyId) {
        long start = System.nanoTime();
        try {
            TopologyMetric ret = new TopologyMetric();
            List<MetricInfo> topologyMetrics = metricCache.getMetricData(topologyId, MetaType.TOPOLOGY);
            List<MetricInfo> componentMetrics = metricCache.getMetricData(topologyId, MetaType.COMPONENT);
            List<MetricInfo> workerMetrics = metricCache.getMetricData(topologyId, MetaType.WORKER);

            MetricInfo dummy = MetricUtils.mkMetricInfo();
            if (topologyMetrics.size() > 0) {
                // get the last min topology metric
                ret.set_topologyMetric(topologyMetrics.get(topologyMetrics.size() - 1));
            } else {
                ret.set_topologyMetric(dummy);
            }
            if (componentMetrics.size() > 0) {
                ret.set_componentMetric(componentMetrics.get(0));
            } else {
                ret.set_componentMetric(dummy);
            }
            if (workerMetrics.size() > 0) {
                ret.set_workerMetric(workerMetrics.get(0));
            } else {
                ret.set_workerMetric(dummy);
            }
            ret.set_taskMetric(dummy);
            ret.set_streamMetric(dummy);
            ret.set_nettyMetric(dummy);

            return ret;
        } finally {
            long end = System.nanoTime();
            SimpleJStormMetric.updateNimbusHistogram("getTopologyMetric", (end - start) / TimeUtils.NS_PER_US);
        }
    }
1199638
private Referenceable getDatabaseReference(String clusterName, String databaseName) throws Exception {
        LOG.debug("Getting reference for database {}", databaseName);
        String typeName = HiveDataTypes.HIVE_DB.getName();

        return getEntityReference(typeName, getDBQualifiedName(clusterName, databaseName));
    }
1372144
def _get_cluster_dict(cluster_name, cluster_ref):
    '''
    
    '''

    log.trace('Building a dictionary representation of cluster \'%s\'', cluster_name)
    props = salt.utils.vmware.get_properties_of_managed_object(
        cluster_ref,
        properties=['configurationEx'])
    res = {'ha': {'enabled': props['configurationEx'].dasConfig.enabled},
           'drs': {'enabled': props['configurationEx'].drsConfig.enabled}}
    # Convert HA properties of interest
    ha_conf = props['configurationEx'].dasConfig
    log.trace('ha_conf = %s', ha_conf)
    res['ha']['admission_control_enabled'] = ha_conf.admissionControlEnabled
    if ha_conf.admissionControlPolicy and \
       isinstance(ha_conf.admissionControlPolicy,
                  vim.ClusterFailoverResourcesAdmissionControlPolicy):
        pol = ha_conf.admissionControlPolicy
        res['ha']['admission_control_policy'] = \
                {'cpu_failover_percent': pol.cpuFailoverResourcesPercent,
                 'memory_failover_percent': pol.memoryFailoverResourcesPercent}
    if ha_conf.defaultVmSettings:
        def_vm_set = ha_conf.defaultVmSettings
        res['ha']['default_vm_settings'] = \
                {'isolation_response': def_vm_set.isolationResponse,
                 'restart_priority': def_vm_set.restartPriority}
    res['ha']['hb_ds_candidate_policy'] = \
            ha_conf.hBDatastoreCandidatePolicy
    if ha_conf.hostMonitoring:
        res['ha']['host_monitoring'] = ha_conf.hostMonitoring
    if ha_conf.option:
        res['ha']['options'] = [{'key': o.key, 'value': o.value}
                                for o in ha_conf.option]
    res['ha']['vm_monitoring'] = ha_conf.vmMonitoring
    # Convert DRS properties
    drs_conf = props['configurationEx'].drsConfig
    log.trace('drs_conf = %s', drs_conf)
    res['drs']['vmotion_rate'] = 6 - drs_conf.vmotionRate
    res['drs']['default_vm_behavior'] = drs_conf.defaultVmBehavior
    # vm_swap_placement
    res['vm_swap_placement'] = props['configurationEx'].vmSwapPlacement
    # Convert VSAN properties
    si = salt.utils.vmware.get_service_instance_from_managed_object(
        cluster_ref)

    if salt.utils.vsan.vsan_supported(si):
        # XXX The correct way of retrieving the VSAN data (on the if branch)
        #  is not supported before 60u2 vcenter
        vcenter_info = salt.utils.vmware.get_service_info(si)
        if int(vcenter_info.build) >= 3634794:  # 60u2
            # VSAN API is fully supported by the VC starting with 60u2
            vsan_conf = salt.utils.vsan.get_cluster_vsan_info(cluster_ref)
            log.trace('vsan_conf = %s', vsan_conf)
            res['vsan'] = {'enabled': vsan_conf.enabled,
                           'auto_claim_storage':
                           vsan_conf.defaultConfig.autoClaimStorage}
            if vsan_conf.dataEfficiencyConfig:
                data_eff = vsan_conf.dataEfficiencyConfig
                res['vsan'].update({
                    # We force compression_enabled to be True/False
                    'compression_enabled':
                    data_eff.compressionEnabled or False,
                    'dedup_enabled': data_eff.dedupEnabled})
        else:  # before 60u2 (no advanced vsan info)
            if props['configurationEx'].vsanConfigInfo:
                default_config = \
                        props['configurationEx'].vsanConfigInfo.defaultConfig
                res['vsan'] = {
                    'enabled': props['configurationEx'].vsanConfigInfo.enabled,
                    'auto_claim_storage': default_config.autoClaimStorage}
    return res
277025
def get_cluster_name(self):
        
        return self._get(
            url=self.url + '/api/cluster-name',
            headers=self.headers,
            auth=self.auth
        )
413674
def cluster_node(self, node_id):
        
        path = '/ws/v1/cluster/nodes/{nodeid}'.format(nodeid=node_id)

        return self.request(path)
42855
private void updateInstaceTypeDescriptionMap() {

		// this.registeredHosts.values().iterator()
		this.instanceTypeDescriptionMap.clear();

		final List<InstanceTypeDescription> instanceTypeDescriptionList = new ArrayList<InstanceTypeDescription>();

		// initialize array which stores the availability counter for each instance type
		final int[] numberOfInstances = new int[this.availableInstanceTypes.length];
		for (int i = 0; i < numberOfInstances.length; i++) {
			numberOfInstances[i] = 0;
		}

		// Shuffle through instance types
		for (int i = 0; i < this.availableInstanceTypes.length; i++) {

			final InstanceType currentInstanceType = this.availableInstanceTypes[i];
			int numberOfMatchingInstances = 0;
			int minNumberOfCPUCores = Integer.MAX_VALUE;
			long minSizeOfPhysicalMemory = Long.MAX_VALUE;
			long minSizeOfFreeMemory = Long.MAX_VALUE;
			final Iterator<ClusterInstance> it = this.registeredHosts.values().iterator();
			while (it.hasNext()) {
				final ClusterInstance clusterInstance = it.next();
				if (clusterInstance.getType().equals(currentInstanceType)) {
					++numberOfMatchingInstances;
					final HardwareDescription hardwareDescription = clusterInstance.getHardwareDescription();
					minNumberOfCPUCores = Math.min(minNumberOfCPUCores, hardwareDescription.getNumberOfCPUCores());
					minSizeOfPhysicalMemory = Math.min(minSizeOfPhysicalMemory,
						hardwareDescription.getSizeOfPhysicalMemory());
					minSizeOfFreeMemory = Math.min(minSizeOfFreeMemory, hardwareDescription.getSizeOfFreeMemory());
				}
			}

			// Update number of instances
			int highestAccommodationNumber = -1;
			int highestAccommodationIndex = -1;
			for (int j = 0; j < this.availableInstanceTypes.length; j++) {
				final int accommodationNumber = canBeAccommodated(j, i);
				// LOG.debug(this.availableInstanceTypes[j].getIdentifier() + " fits into "
				// + this.availableInstanceTypes[i].getIdentifier() + " " + accommodationNumber + " times");
				if (accommodationNumber > 0) {
					numberOfInstances[j] += numberOfMatchingInstances * accommodationNumber;
					if (accommodationNumber > highestAccommodationNumber) {
						highestAccommodationNumber = accommodationNumber;
						highestAccommodationIndex = j;
					}
				}
			}

			// Calculate hardware description
			HardwareDescription pessimisticHardwareDescription = null;
			if (minNumberOfCPUCores < Integer.MAX_VALUE && minSizeOfPhysicalMemory < Long.MAX_VALUE
				&& minSizeOfFreeMemory < Long.MAX_VALUE) {

				pessimisticHardwareDescription = HardwareDescriptionFactory.construct(minNumberOfCPUCores,
					minSizeOfPhysicalMemory, minSizeOfFreeMemory);

			} else {

				if (highestAccommodationIndex < i) { // Since highestAccommodationIndex smaller than my index, the
														// target instance must be more powerful

					final InstanceTypeDescription descriptionOfLargerInstanceType = instanceTypeDescriptionList
						.get(highestAccommodationIndex);
					if (descriptionOfLargerInstanceType.getHardwareDescription() != null) {
						final HardwareDescription hardwareDescriptionOfLargerInstanceType = descriptionOfLargerInstanceType
							.getHardwareDescription();

						final int numCores = hardwareDescriptionOfLargerInstanceType.getNumberOfCPUCores()
							/ highestAccommodationNumber;
						final long physMem = hardwareDescriptionOfLargerInstanceType.getSizeOfPhysicalMemory()
							/ highestAccommodationNumber;
						final long freeMem = hardwareDescriptionOfLargerInstanceType.getSizeOfFreeMemory()
							/ highestAccommodationNumber;

						pessimisticHardwareDescription = HardwareDescriptionFactory.construct(numCores, physMem,
							freeMem);
					}
				}
			}

			instanceTypeDescriptionList.add(InstanceTypeDescriptionFactory.construct(currentInstanceType,
				pessimisticHardwareDescription, numberOfInstances[i]));
		}

		final Iterator<InstanceTypeDescription> it = instanceTypeDescriptionList.iterator();
		while (it.hasNext()) {

			final InstanceTypeDescription itd = it.next();
			this.instanceTypeDescriptionMap.put(itd.getInstanceType(), itd);
		}
	}
1267648
private void displayClusterInfo() {
        Metadata metadata = m_cluster.getMetadata();
        m_logger.info("Connected to cluster with topography:");
        RoundRobinPolicy policy = new RoundRobinPolicy();
        for (Host host : metadata.getAllHosts()) {
            m_logger.info("   Host {}: datacenter: {}, rack: {}, distance: {}",
                          new Object[]{host.getAddress(), host.getDatacenter(), 
                host.getRack(), policy.distance(host)});
        }
        m_logger.info("Database contains {} keyspaces", metadata.getKeyspaces().size());
    }
1262814
def generate_nodes(self, topology):
        
        nodes = []

        devices = topology['devices']
        hypervisors = topology['conf']

        for device in sorted(devices):
            hv_id = devices[device]['hv_id']
            try:
                tmp_node = Node(hypervisors[hv_id], self.port_id)
            except IndexError:
                tmp_node = Node({}, self.port_id)
            # Start building the structure
            tmp_node.node['properties']['name'] = device
            tmp_node.node['id'] = devices[device]['node_id']
            tmp_node.node['x'] = devices[device]['x']
            tmp_node.node['y'] = devices[device]['y']
            tmp_node.device_info['from'] = devices[device]['from']
            tmp_node.device_info['type'] = devices[device]['type']
            tmp_node.device_info['desc'] = devices[device]['desc']

            if 'ext_conf' in devices[device]:
                tmp_node.device_info['ext_conf'] = devices[device]['ext_conf']

            # Node Label
            tmp_node.node['label']['text'] = device
            if 'hx' in devices[device] and 'hy' in devices[device]:
                tmp_node.node['label']['x'] = devices[device]['hx']
                tmp_node.node['label']['y'] = devices[device]['hy']

            if 'model' in devices[device]:
                tmp_node.device_info['model'] = devices[device]['model']
            else:
                tmp_node.device_info['model'] = ''

            tmp_node.set_description()
            tmp_node.set_type()

            # Now lets process the rest
            for item in sorted(devices[device]):
                tmp_node.add_device_items(item, devices[device])

            if tmp_node.device_info['type'] == 'Router':
                tmp_node.add_info_from_hv()
                tmp_node.node['router_id'] = devices[device]['node_id']
                tmp_node.calc_mb_ports()

                for item in sorted(tmp_node.node['properties']):
                    if item.startswith('slot'):
                        tmp_node.add_slot_ports(item)
                    elif item.startswith('wic'):
                        tmp_node.add_wic_ports(item)

                # Add default ports to 7200 and 3660
                if tmp_node.device_info['model'] == 'c7200':
                    # tmp_node.add_slot_ports('slot0')
                    # C7200 doesnt have any ports by default
                    pass
                elif tmp_node.device_info['model'] == 'c3600' \
                        and tmp_node.device_info['chassis'] == '3660':
                    tmp_node.node['properties']['slot0'] = 'Leopard-2FE'

                # Calculate the router links
                tmp_node.calc_device_links()

            elif tmp_node.device_info['type'] == 'Cloud':
                try:
                    tmp_node.calc_cloud_connection()
                except RuntimeError as err:
                    print(err)

            elif tmp_node.device_info['type'] == 'FrameRelaySwitch':
                tmp_node.process_mappings()

            elif tmp_node.device_info['type'] == 'VirtualBoxVM':
                tmp_node.add_to_virtualbox()
                tmp_node.add_vm_ethernet_ports()
                tmp_node.calc_device_links()

            elif tmp_node.device_info['type'] == 'QemuVM':
                tmp_node.add_to_qemu()
                tmp_node.set_qemu_symbol()
                tmp_node.add_vm_ethernet_ports()
                tmp_node.calc_device_links()

            # Get the data we need back from the node instance
            self.links.extend(tmp_node.links)
            self.configs.extend(tmp_node.config)
            self.port_id += tmp_node.get_nb_added_ports(self.port_id)

            nodes.append(tmp_node.node)

        return nodes