private void removeNode(Entity member, String name) { synchronized (clusterMutex) { LOG.info("Removing node {}: {}; {} from cluster", new Object[] { this, member, name }); Map<Entity, String> nodes = MutableMap.copyOf(sensors().get(ETCD_CLUSTER_NODES)); nodes.remove(member); recalculateClusterAddresses(nodes); member.sensors().set(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.FALSE); } }
@Override public String getSubnetIp() { String containerAddress = dockerContainer.sensors().get(Attributes.SUBNET_ADDRESS); if (Strings.isEmpty(containerAddress)) { String containerId = checkNotNull(dockerContainer.getContainerId(), "containerId"); containerAddress = dockerContainer.getDockerHost() .runDockerCommand("inspect --format={{.NetworkSettings.IPAddress}} " + containerId) .trim(); } return containerAddress; }
@Test public void testNeverGrowColdPool() throws Exception { resizable.resize(2); resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(2, 1000L, 2*10L, 2*20L)); Thread.sleep(SHORT_WAIT_MS); assertEquals(resizable.getCurrentSize(), (Integer)2); }
@Override public Set<String> getPrivateAddresses() { if (dockerContainer.config().get(SdnAttributes.SDN_ENABLE)) { return ImmutableSet.copyOf(dockerContainer.sensors().get(DockerContainer.CONTAINER_ADDRESSES)); } else { return ImmutableSet.of(getSubnetIp()); } }
private void onHostChanged(Entity item) { synchronized (hostMutex) { boolean exists = getDockerHostCluster().hasMember(item); Boolean running = item.sensors().get(SERVICE_UP); if (exists && running && item.sensors().get(SdnAgent.SDN_AGENT) == null) { onHostAdded(item); } else if (!exists) { onHostRemoved(item); } } }
@Override public void removeHost(DockerHost host) { SdnAgent agent = host.sensors().get(SdnAgent.SDN_AGENT); if (agent == null) { LOG.warn("{} cannot find overlay service: {}", this, host); return; } agent.stop(); getAgents().removeMember(agent); Entities.unmanage(agent); if (LOG.isDebugEnabled()) LOG.debug("{} removed overlay plugin {}", this, agent); }
@Override public void removeHost(DockerHost host) { SdnAgent agent = host.sensors().get(SdnAgent.SDN_AGENT); if (agent == null) { LOG.warn("{} cannot find calico service: {}", this, host); return; } agent.stop(); getAgents().removeMember(agent); Entities.unmanage(agent); if (LOG.isDebugEnabled()) LOG.debug("{} removed calico plugin {}", this, agent); }
@Override public InetAddress getNextAgentAddress(String agentId) { Entity agent = getManagementContext().getEntityManager().getEntity(agentId); String address = agent.sensors().get(CalicoNode.DOCKER_HOST).sensors().get(Attributes.SUBNET_ADDRESS); try { return InetAddress.getByName(address); } catch (UnknownHostException uhe) { throw Exceptions.propagate(uhe); } }
@Override public void disconnect(DockerContainer container, VirtualNetwork network) { synchronized (network) { MutableSet<Entity> connected = MutableSet.copyOf(network.sensors().get(VirtualNetwork.CONNECTED_CONTAINERS)); connected.remove(container); network.sensors().set(VirtualNetwork.CONNECTED_CONTAINERS, connected.asImmutableCopy()); } network.relations().remove(VirtualNetwork.CONNECTED, container); container.relations().remove(VirtualNetwork.CONNECTED, network); }
@Override public void connect(DockerContainer container, VirtualNetwork network) { synchronized (network) { MutableSet<Entity> connected = MutableSet.copyOf(network.sensors().get(VirtualNetwork.CONNECTED_CONTAINERS)); connected.add(container); network.sensors().set(VirtualNetwork.CONNECTED_CONTAINERS, connected.asImmutableCopy()); } network.relations().add(VirtualNetwork.ATTACHED, container); container.relations().add(VirtualNetwork.CONNECTED, network); }
public void run() { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e)); assertAttributeEquals(e, SequenceGroup.SEQUENCE_VALUE, 1); AtomicInteger state = group.sensors().get(SequenceGroup.SEQUENCE_STATE); assertEquals(state.get(), 2); }}); }
@Override public boolean apply(Entity input) { return Boolean.TRUE.equals(input.sensors().get(Startable.SERVICE_UP)); } @Override
@Override public boolean apply(@Nullable Entity input) { List<String> networks = input.sensors().get(SdnAttributes.ATTACHED_NETWORKS); if (networks != null) { return networks.contains(id); } else { return false; } } }
/** Checks if the SDN provider is of the specified type. */ public static final boolean isSdnProvider(Entity entity, String providerName) { if (entity.config().get(SdnAttributes.SDN_ENABLE)) { Entity sdn = entity.sensors().get(SdnAttributes.SDN_PROVIDER); if (sdn == null) return false; return sdn.getEntityType().getSimpleName().equalsIgnoreCase(providerName); } else return false; }
private String getDockerRegistryOpts() { String registryUrl = entity.config().get(DockerInfrastructure.DOCKER_IMAGE_REGISTRY_URL); if (Strings.isNonBlank(registryUrl)) { return format("--insecure-registry %s", registryUrl); } if (entity.config().get(DockerInfrastructure.DOCKER_SHOULD_START_REGISTRY)) { String firstHostname = entity.sensors().get(DynamicGroup.FIRST).sensors().get(Attributes.HOSTNAME); Integer registryPort = entity.config().get(DockerInfrastructure.DOCKER_REGISTRY_PORT); return format("--insecure-registry %s:%d", firstHostname, registryPort); } return null; }
@Override public boolean isRunning() { // Spawns a container for duration of command, so take the host lock getEntity().sensors().get(SdnAgent.DOCKER_HOST).getDynamicLocation().getLock().lock(); try { return newScript(MutableMap.of(USE_PID_FILE, false), CHECK_RUNNING) .body.append(BashCommands.sudo(getWeaveCommand() + " status")) .execute() == 0; } finally { getEntity().sensors().get(SdnAgent.DOCKER_HOST).getDynamicLocation().getLock().unlock(); } }
@Override public void removeHost(DockerHost host) { SdnAgent agent = host.sensors().get(SdnAgent.SDN_AGENT); if (agent == null) { LOG.warn("{} cannot find Weave service: {}", this, host); return; } agent.stop(); getAgents().removeMember(agent); Entities.unmanage(agent); LOG.debug("{} removed Weave service {}", this, agent); }
@Override public void createSubnet(String subnetId, Cidr subnetCidr) { Iterable<String> opts = Iterables.transform(getDockerNetworkCreateOpts(), StringFunctions.prepend("--opt ")); getEntity().sensors().get(SdnAgent.DOCKER_HOST).runDockerCommand( String.format("network create --driver %s %s --subnet=%s %s", getDockerNetworkDriver(), Joiner.on(' ').join(opts), subnetCidr, subnetId)); }
@Test public void testMoveDecisionIgnoresDemandFromItself() throws Exception { // Set-up containers and items. MockContainerEntity containerA = newContainer(app, loc1, "A"); MockContainerEntity containerB = newContainer(app, loc2, "B"); MockItemEntity item1 = newItem(app, containerA, "1"); MockItemEntity item2 = newItem(app, containerB, "2"); item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item1, 100d)); item2.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); Thread.sleep(SHORT_WAIT_MS); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item1), containerB, ImmutableList.of(item2))); }
@Test public void testNoopIfDemandIsTiny() throws Exception { // Set-up containers and items. MockContainerEntity containerA = newContainer(app, loc1, "A"); MockContainerEntity containerB = newContainer(app, loc2, "B"); MockItemEntity item1 = newItem(app, containerA, "1"); MockItemEntity item2 = newItem(app, containerB, "2"); item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 0.1d)); Thread.sleep(SHORT_WAIT_MS); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item1), containerB, ImmutableList.of(item2))); }