Package com.netflix.exhibitor.core.state

Examples of com.netflix.exhibitor.core.state.ServerList


    public Response getSystemState(@Context Request request) throws Exception
    {
        InstanceConfig              config = context.getExhibitor().getConfigManager().getConfig();

        String                      response = new FourLetterWord(FourLetterWord.Word.RUOK, config, context.getExhibitor().getConnectionTimeOutMs()).getResponse();
        ServerList                  serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
        ServerSpec                  us = Iterables.find(serverList.getSpecs(), ServerList.isUs(context.getExhibitor().getThisJVMHostname()), null);

        ObjectNode                  mainNode = JsonNodeFactory.instance.objectNode();
        ObjectNode                  configNode = JsonNodeFactory.instance.objectNode();
        ObjectNode                  controlPanelNode = JsonNodeFactory.instance.objectNode();
View Full Code Here


    }

    boolean serverListHasSynced()
    {
        String      targetServersSpec = config.getRollingConfig().getString(StringConfigs.SERVERS_SPEC);
        ServerList  targetServerList = new ServerList(targetServersSpec);
        return targetServerList.equals(currentInstanceState.getServerList());
    }
View Full Code Here

    }

    @Override
    public ServerList createPotentialServerList()
    {
        ServerList configuredServerList = clusterState.getConfiguredServerList();
        Map<ServerSpec, InstanceStateTypes> statusMap = clusterState.buildStatusMap();

        List<ServerSpec>        newList = Lists.newArrayList();
        for ( ServerSpec spec : configuredServerList.getSpecs() )
        {
            if ( statusMap.get(spec) != InstanceStateTypes.DOWN )
            {
                newList.add(spec);
            }
        }
        if ( newList.size() >= fixedEnsembleSize )
        {
            return configuredServerList;    // no room for us
        }

        int                 standardTypeCount = 0;
        for ( ServerSpec spec : newList )
        {
            if ( spec.getServerType() == ServerType.STANDARD )
            {
                ++standardTypeCount;
            }
        }

        int observerThreshold = exhibitor.getConfigManager().getConfig().getInt(IntConfigs.OBSERVER_THRESHOLD);
        ServerType serverType = ((observerThreshold > 0) && (standardTypeCount >= observerThreshold)) ? ServerType.OBSERVER : ServerType.STANDARD;

        int existingMaxId = FlexibleEnsembleBuilder.getExistingMaxId(configuredServerList);
        ServerSpec us = new ServerSpec(exhibitor.getThisJVMHostname(), existingMaxId + 1, serverType);
        newList.add(us);

        return new ServerList(newList);
    }
View Full Code Here

{
    private final List<String>      rollingHostNames;

    RollingHostNamesBuilder(InstanceConfig rootConfig, InstanceConfig rollingConfig, String leaderHostname)
    {
        ServerList  rootServers = new ServerList(rootConfig.getString(StringConfigs.SERVERS_SPEC));
        ServerList  rollingServers = new ServerList(rollingConfig.getString(StringConfigs.SERVERS_SPEC));

        Set<String>     newServers = Sets.difference(Sets.newTreeSet(rollingServers.getHostnames()), Sets.newTreeSet(rootServers.getHostnames()));
        Set<String>     unchangedServers = Sets.intersection(Sets.newTreeSet(rollingServers.getHostnames()), Sets.newTreeSet(rootServers.getHostnames()));

        ImmutableList.Builder<String> builder = ImmutableList.builder();
        builder.addAll(newServers); // new servers need to be started first as the others will try to communicate with them. You may have issues if there is more than 1 new server
        if ( (leaderHostname != null) && unchangedServers.contains(leaderHostname) )
        {
View Full Code Here

        return configuredServerList.get();
    }

    Map<ServerSpec, InstanceStateTypes> buildStatusMap()
    {
        ServerList serverList = configuredServerList.get();

        ImmutableMap.Builder<ServerSpec, InstanceStateTypes> builder = ImmutableMap.builder();
        List<ServerStatus> currentStatuses = statuses.get();
        for ( ServerStatus status : currentStatuses )
        {
            ServerSpec spec = serverList.getSpec(status.getHostname());
            if ( spec != null )
            {
                builder.put(spec, status.getInstanceStateType());
            }
            else
View Full Code Here

    void clear()
    {
        statuses.set(Lists.<ServerStatus>newArrayList());
        updateTimeMs.set(System.currentTimeMillis());
        configuredServerList.set(new ServerList(Lists.<ServerSpec>newArrayList()));
    }
View Full Code Here

        if ( exhibitor.getMonitorRunningInstance().getCurrentInstanceState() == InstanceStateTypes.LATENT )
        {
            return true;    // this instance hasn't warmed up yet
        }

        ServerList serverList = new ServerList(exhibitor.getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC));
        List<ServerStatus> statuses = getStatuses(serverList);
        clusterState.update(serverList, statuses);

        EnsembleBuilder ensembleBuilder = (exhibitor.getConfigManager().getConfig().getInt(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE) > 0) ? new FixedEnsembleBuilder(exhibitor, clusterState) : new FlexibleEnsembleBuilder(exhibitor, clusterState);

        if ( !ensembleBuilder.newEnsembleNeeded() )
        {
            return true;
        }

        if ( !applyAllAtOnce() && !clusterState.isInQuorum() )
        {
            exhibitor.getLog().add(ActivityLog.Type.INFO, "Ensemble is not currently in quorum. Automatic Instance Management will wait for quorum. NOTE: if \"Apply All At Once\" is set to \"yes\", this quorum check is not needed.");
            return true;
        }

        int settlingPeriodMs = exhibitor.getConfigManager().getConfig().getInt(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS);
        if ( !clusterState.isStable(settlingPeriodMs) )
        {
            exhibitor.getLog().add(ActivityLog.Type.INFO, "Ensemble state is not yet stable. Automatic Instance Management will wait for stability.");
            return true;
        }

        PseudoLock lock = exhibitor.getConfigManager().newConfigBasedLock();
        try
        {
            if ( lock.lock(exhibitor.getLog(), Exhibitor.AUTO_INSTANCE_MANAGEMENT_PERIOD_MS / 2, TimeUnit.MILLISECONDS) )
            {
                ServerList potentialServerList = ensembleBuilder.createPotentialServerList();
                if ( !potentialServerList.equals(serverList) )  // otherwise, no change
                {
                    if ( potentialServerList.getSpecs().size() == 0 )
                    {
                        exhibitor.getLog().add(ActivityLog.Type.INFO, "Automatic Instance Management skipped because new potential server list is empty");
                    }
                    else
                    {
                        exhibitor.getLog().add(ActivityLog.Type.INFO, "Automatic Instance Management will change the server list: " + serverList + " ==> " + potentialServerList);
                        adjustConfig(potentialServerList.toSpecString(), clusterState.getLeaderHostname());
                    }
                }
            }
        }
        finally
View Full Code Here

public class TestRollingConfigChange
{
    @Test
    public void testFailedQuorum() throws Exception
    {
        ServerList          serverList = new ServerList("1:one,2:two,3:three");

        RemoteInstanceRequestClient     mockClient = new RemoteInstanceRequestClient()
        {
            @Override
            public void close() throws IOException
            {
            }

            @Override
            public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception
            {
                return clazz.cast("foo");
            }
        };

        ActivityLog         log = new ActivityLog(100);
        ActivityQueue       activityQueue = new ActivityQueue();
        Exhibitor           mockExhibitor = Mockito.mock(Exhibitor.class);
        MonitorRunningInstance mockMonitorRunningInstance = makeMockMonitorRunningInstance();
        Mockito.when(mockExhibitor.getMonitorRunningInstance()).thenReturn(mockMonitorRunningInstance);
        Mockito.when(mockExhibitor.getLog()).thenReturn(log);
        Mockito.when(mockExhibitor.getActivityQueue()).thenReturn(activityQueue);
        Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn("one");
        Mockito.when(mockExhibitor.getRemoteInstanceRequestClient()).thenReturn(mockClient);

        final AtomicLong    modified = new AtomicLong(1);
        ConfigProvider      provider = new ConfigProvider()
        {
            private volatile ConfigCollection      config = new PropertyBasedInstanceConfig(new Properties(), new Properties());

            @Override
            public void start() throws Exception
            {
            }

            @Override
            public void close() throws IOException
            {
            }

            @Override
            public LoadedInstanceConfig loadConfig() throws Exception
            {
                return new LoadedInstanceConfig(config, modified.get());
            }

            @Override
            public PseudoLock newPseudoLock() throws Exception
            {
                return null;
            }

            @Override
            public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception
            {
                this.config = config;
                modified.incrementAndGet();
                return loadConfig();
            }
        };

        InstanceState       state = new InstanceState(serverList, InstanceStateTypes.NOT_SERVING, new RestartSignificantConfig(null));

        final AtomicBoolean hasBeenCanceled = new AtomicBoolean(false);
        ConfigManager       manager = new ConfigManager(mockExhibitor, provider, 10)
        {
            @Override
            public synchronized void cancelRollingConfig(CancelMode mode) throws Exception
            {
                super.cancelRollingConfig(mode);
                hasBeenCanceled.set(true);
            }
        };
        manager.start();
        try
        {
            Properties                      properties = new Properties();
            properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), serverList.toSpecString());
            PropertyBasedInstanceConfig     config = new PropertyBasedInstanceConfig(properties, DefaultProperties.get(null));
            manager.startRollingConfig(config.getRootConfig(), null);

            String      hostname = manager.getRollingConfigState().getRollingHostNames().get(0);
            Assert.assertTrue(manager.isRolling());
View Full Code Here

    }

    @Test
    public void testLongQuorumSuccess() throws Exception
    {
        ServerList          serverList = new ServerList("1:one");

        RemoteInstanceRequestClient     mockClient = new RemoteInstanceRequestClient()
        {
            @Override
            public void close() throws IOException
            {
            }

            @Override
            public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception
            {
                throw new Exception();
            }
        };

        ActivityLog         log = new ActivityLog(100);
        ActivityQueue       activityQueue = new ActivityQueue();
        Exhibitor           mockExhibitor = Mockito.mock(Exhibitor.class);
        MonitorRunningInstance mockMonitorRunningInstance = makeMockMonitorRunningInstance();
        Mockito.when(mockExhibitor.getMonitorRunningInstance()).thenReturn(mockMonitorRunningInstance);
        Mockito.when(mockExhibitor.getLog()).thenReturn(log);
        Mockito.when(mockExhibitor.getActivityQueue()).thenReturn(activityQueue);
        Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn("one");
        Mockito.when(mockExhibitor.getRemoteInstanceRequestClient()).thenReturn(mockClient);

        ConfigProvider      provider = new ConfigWrapper(new AtomicLong(1));

        Properties                      properties = new Properties();
        properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), serverList.toSpecString());
        properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROLLING_PROPERTY_PREFIX), serverList.toSpecString());
        properties.setProperty(PropertyBasedInstanceConfig.PROPERTY_ROLLING_HOSTNAMES, "one");
        properties.setProperty(PropertyBasedInstanceConfig.PROPERTY_ROLLING_HOSTNAMES_INDEX, "0");
        PropertyBasedInstanceConfig     config = new PropertyBasedInstanceConfig(properties, DefaultProperties.get(null));
        provider.storeConfig(config, 0);
View Full Code Here

    }

    @Test
    public void testAllDownInstances() throws Exception
    {
        ServerList          serverList = new ServerList("1:one,2:two,3:three");

        RemoteInstanceRequestClient     mockClient = new RemoteInstanceRequestClient()
        {
            @Override
            public void close() throws IOException
            {
            }

            @Override
            public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception
            {
                throw new Exception();
            }
        };

        ActivityLog         log = new ActivityLog(100);
        ActivityQueue       activityQueue = new ActivityQueue();
        Exhibitor           mockExhibitor = Mockito.mock(Exhibitor.class);
        MonitorRunningInstance mockMonitorRunningInstance = makeMockMonitorRunningInstance();
        Mockito.when(mockExhibitor.getMonitorRunningInstance()).thenReturn(mockMonitorRunningInstance);
        Mockito.when(mockExhibitor.getLog()).thenReturn(log);
        Mockito.when(mockExhibitor.getActivityQueue()).thenReturn(activityQueue);
        Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn("_xxxx_");
        Mockito.when(mockExhibitor.getRemoteInstanceRequestClient()).thenReturn(mockClient);

        ConfigProvider      provider = new ConfigWrapper(new AtomicLong(1));
        ConfigManager       manager = new ConfigManager(mockExhibitor, provider, 10, 1);
        manager.start();
        try
        {
            Properties                      properties = new Properties();
            properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), serverList.toSpecString());
            PropertyBasedInstanceConfig     config = new PropertyBasedInstanceConfig(properties, DefaultProperties.get(null));
            manager.startRollingConfig(config.getRootConfig(), null);

            Assert.assertFalse(manager.isRolling());
        }
View Full Code Here

TOP

Related Classes of com.netflix.exhibitor.core.state.ServerList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.