Examples of ServerList


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

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

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

    }

    @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

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

    }

    @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

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

    }

    @Test
    public void testDownMiddleInstance() throws Exception
    {
        ServerList          serverList = new ServerList("1:aaa,2:two,3:zzz");

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

            @Override
            public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception
            {
                if ( remoteUri.getHost().equals("two") )
                {
                    throw new 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 ConfigWrapper(modified);

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

        ConfigManager       manager = new ConfigManager(mockExhibitor, provider, 10);
        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);

            for ( String hostname : manager.getRollingConfigState().getRollingHostNames() )
            {
View Full Code Here

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

    }

    @Test
    public void testDownLastInstance() 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
            {
                if ( remoteUri.getHost().equals("two") )
                {
                    throw new 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.SERVING, new RestartSignificantConfig(null));

        ConfigManager       manager = new ConfigManager(mockExhibitor, provider, 10);
        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);

            for ( String hostname : manager.getRollingConfigState().getRollingHostNames() )
            {
View Full Code Here

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

    }

    @Test
    public void testChange() 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.SERVING, new RestartSignificantConfig(null));

        ConfigManager       manager = new ConfigManager(mockExhibitor, provider, 10);
        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);

            for ( String hostname : manager.getRollingConfigState().getRollingHostNames() )
            {
View Full Code Here

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

        return false;
    }

    public ServerList  createPotentialServerList()
    {
        ServerList configuredServerList = clusterState.getConfiguredServerList();
        int existingMaxId = getExistingMaxId(configuredServerList);

        List<ServerSpec>        newList = Lists.newArrayList();

        Set<String> addedHostnames = Sets.newHashSet();
        for ( ServerStatus status : clusterState.getLiveInstances() )
        {
            ServerSpec spec = configuredServerList.getSpec(status.getHostname());
            if ( spec == null )
            {
                spec = new ServerSpec(status.getHostname(), ++existingMaxId, ServerType.STANDARD);
                addedHostnames.add(spec.getHostname());
            }
            newList.add(spec);
        }

        if ( usState.getUs() == null )
        {
            ServerSpec      spec = new ServerSpec(exhibitor.getThisJVMHostname(), ++existingMaxId, ServerType.STANDARD);
            addedHostnames.add(spec.getHostname());
            newList.add(spec);
        }

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

        int         observerThreshold = exhibitor.getConfigManager().getConfig().getInt(IntConfigs.OBSERVER_THRESHOLD);
        if ( observerThreshold > 0 )
        {
            for ( int i = 0; (standardTypeCount >= observerThreshold) && (i < newList.size()); ++i )
            {
                ServerSpec      spec = newList.get(i);
                if ( addedHostnames.contains(spec.getHostname()) )  // i.e. don't change existing instances to observer
                {
                    newList.set(i, new ServerSpec(spec.getHostname(), spec.getServerId(), ServerType.OBSERVER));
                    --standardTypeCount;
                }
            }
        }

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

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

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getClusterStatus() throws Exception
    {
        InstanceConfig      config = context.getExhibitor().getConfigManager().getConfig();
        ServerList          serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));

        ClusterStatusTask   task = new ClusterStatusTask(context.getExhibitor(), serverList.getSpecs());
        List<ServerStatus>  statuses = context.getExhibitor().getForkJoinPool().invoke(task);

        GenericEntity<List<ServerStatus>> entity = new GenericEntity<List<ServerStatus>>(statuses){};
        return Response.ok(entity).build();
    }
View Full Code Here

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

        InstanceConfig      config = context.getExhibitor().getConfigManager().getConfig();

        ObjectNode          node = JsonNodeFactory.instance.objectNode();

        ArrayNode           serversNode = JsonNodeFactory.instance.arrayNode();
        ServerList          serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
        for ( ServerSpec spec : serverList.getSpecs() )
        {
            serversNode.add(spec.getHostname());
        }
        node.put("servers", serversNode);
        node.put("port", config.getInt(IntConfigs.CLIENT_PORT));
View Full Code Here

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

    {
        InstanceConfig      config = context.getExhibitor().getConfigManager().getConfig();

        StringBuilder       response = new StringBuilder();

        ServerList          serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
        response.append("count=").append(serverList.getSpecs().size());

        int                 index = 0;
        for ( ServerSpec spec : serverList.getSpecs() )
        {
            response.append("&server").append(index++).append("=").append(URLEncoder.encode(spec.getHostname(), "UTF-8"));
        }

        response.append("&port=").append(config.getInt(IntConfigs.CLIENT_PORT));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.