Package com.sonyericsson.hudson.plugins.gerrit.trigger.config

Examples of com.sonyericsson.hudson.plugins.gerrit.trigger.config.ReplicationConfig


         * If so, the user will see a warning to read the help regarding replication
         * @return true if so.
         */
        public boolean isReplicationEnabled() {
            for (GerritServer server : PluginImpl.getInstance().getServers()) {
                ReplicationConfig replicationConfig = server.getConfig().getReplicationConfig();
                if (replicationConfig != null) {
                    return replicationConfig.isEnableReplication();
                }
            }
            return false;
        }
View Full Code Here


        List<GerritSlave> slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
        assertNotNull(slaves);
        assertEquals(0, slaves.size());

        // ReplicationConfig is defined but is not configured
        ReplicationConfig replicationConfigMock = mock(ReplicationConfig.class);
        when(configMock.getReplicationConfig()).thenReturn(replicationConfigMock);
        slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
        assertNotNull(slaves);
        assertEquals(0, slaves.size());
    }
View Full Code Here

     * Tests {@link GerritTrigger#gerritSlavesToWaitFor(String)}. It should
     * return slaves configured globally, at the administrative level.
     */
    @Test
    public void shouldReturnGlobalSlavesWhenConfigured() {
        ReplicationConfig replicationConfigMock = setupReplicationConfigMock();
        GerritTrigger gerritTrigger = Setup.createDefaultTrigger(null);

        // Replication is enable but slave list is null
        when(replicationConfigMock.isEnableReplication()).thenReturn(true);
        when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(false);
        when(replicationConfigMock.getGerritSlaves()).thenReturn(null);
        List<GerritSlave> slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
        assertNotNull(slaves);
        assertEquals(0, slaves.size());

        // Replication is enable but slave list is empty
        when(replicationConfigMock.isEnableReplication()).thenReturn(true);
        when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(false);
        when(replicationConfigMock.getGerritSlaves()).thenReturn(Collections.<GerritSlave> emptyList());
        slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
        assertNotNull(slaves);
        assertEquals(0, slaves.size());

        // ReplicationConfig is enabled and slaves are defined
        List<GerritSlave> expectedSlaves = Arrays.asList(new GerritSlave("slave1", "slave1", 1234),
            new GerritSlave("slave2", "slave2", 1234));
        when(replicationConfigMock.isEnableReplication()).thenReturn(true);
        when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(false);
        when(replicationConfigMock.getGerritSlaves()).thenReturn(expectedSlaves);
        slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
        assertNotNull(slaves);
        assertEquals(2, slaves.size());
        assertEquals(expectedSlaves, slaves);
    }
View Full Code Here

     * Tests {@link GerritTrigger#gerritSlavesToWaitFor(String)}. It should
     * return slave configured at the job level.
     */
    @Test
    public void shouldReturnSlaveSelectedInJobWhenConfigured() {
        ReplicationConfig replicationConfigMock = setupReplicationConfigMock();
        GerritTrigger gerritTrigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, false, true,
                false, false, "", "", "", "", "", "", "", null, PluginImpl.DEFAULT_SERVER_NAME, "slaveUUID", null,
                false, false, "", null);

        when(replicationConfigMock.isEnableReplication()).thenReturn(true);
        when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(true);
        GerritSlave expectedSlave = new GerritSlave("slaveUUID", "slave1", "slave1", 1234);
        when(replicationConfigMock.getGerritSlave("slaveUUID", true)).thenReturn(expectedSlave);
        List<GerritSlave> slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
        assertNotNull(slaves);
        assertEquals(1, slaves.size());
        assertEquals(expectedSlave, slaves.get(0));
    }
View Full Code Here

     * Tests {@link GerritTrigger#gerritSlavesToWaitFor(String serverName)}. It should
     * return default slave when slave configure at the job level does not exist.
     */
    @Test
    public void shouldReturnDefaultSlaveWhenJobConfiguredSlaveDoesNotExist() {
        ReplicationConfig replicationConfigMock = setupReplicationConfigMock();
        GerritTrigger gerritTrigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, false, true,
                false, false, "", "", "", "", "", "", "", null, PluginImpl.DEFAULT_SERVER_NAME, "slaveUUID", null,
                false, false, "", null);

        // Replication is configured at job level but slave and default no longer exist.
        when(replicationConfigMock.isEnableReplication()).thenReturn(true);
        when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(true);
        when(replicationConfigMock.getGerritSlave("slaveUUID", true)).thenReturn(null);
        List<GerritSlave> slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
        assertNotNull(slaves);
        assertEquals(0, slaves.size());

        // Replication is configured at job level but slave no longer exist
        when(replicationConfigMock.isEnableReplication()).thenReturn(true);
        when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(true);
        GerritSlave expectedSlave = new GerritSlave("defaultSlaveUUID", "defaultSlave", "defaultSlave", 1234);
        when(replicationConfigMock.getGerritSlave("slaveUUID", true)).thenReturn(expectedSlave);
        slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
        assertNotNull(slaves);
        assertEquals(1, slaves.size());
        assertEquals(expectedSlave, slaves.get(0));
    }
View Full Code Here

     * Setup a ReplicationConfig mock
     * @return the ReplicationConfig mock
     */
    private ReplicationConfig setupReplicationConfigMock() {
        IGerritHudsonTriggerConfig configMock = setupSeverConfigMock();
        ReplicationConfig replicationConfigMock = mock(ReplicationConfig.class);
        when(configMock.getReplicationConfig()).thenReturn(replicationConfigMock);
        return replicationConfigMock;
    }
View Full Code Here

        if (gerritServer == null) {
            logger.warn("Could not find server: {}", serverName);
            return gerritSlaves;
        }

        ReplicationConfig replicationConfig = gerritServer.getConfig().getReplicationConfig();
        if (replicationConfig != null && replicationConfig.isEnableReplication()) {
            if (replicationConfig.isEnableSlaveSelectionInJobs()) {
                GerritSlave gerritSlave = replicationConfig.getGerritSlave(gerritSlaveId, true);
                if (gerritSlave != null) {
                    gerritSlaves.add(gerritSlave);
                }
            } else {
                List<GerritSlave> globalSlaves = replicationConfig.getGerritSlaves();
                if (globalSlaves != null) {
                    gerritSlaves.addAll(globalSlaves);
                }
            }
        }
View Full Code Here

         */
        public boolean isSlaveSelectionAllowedInJobs() {
            //since we cannot create/remove drop down when the server is selected,
            //as soon as one of the server allow slave selection, we must display it.
            for (GerritServer server : PluginImpl.getInstance().getServers()) {
                ReplicationConfig replicationConfig = server.getConfig().getReplicationConfig();
                if (replicationConfig != null && replicationConfig.isEnableSlaveSelectionInJobs()) {
                    return true;
                }
            }
            return false;
        }
View Full Code Here

            if (server == null) {
                logger.warn(Messages.CouldNotFindServer(serverName));
                items.add(Messages.CouldNotFindServer(serverName), "");
                return items;
            }
            ReplicationConfig replicationConfig = server.getConfig().getReplicationConfig();
            if (replicationConfig == null) {
                items.add(Messages.ReplicationNotConfigured(), "");
                return items;
            } else if (!replicationConfig.isEnableReplication()) {
                items.add(Messages.ReplicationNotConfigured(), "");
                return items;
            } else if (!replicationConfig.isEnableSlaveSelectionInJobs()) {
                items.add(Messages.SlaveSelectionInJobsDisabled(), "");
                return items;
            }
            for (GerritSlave slave : replicationConfig.getGerritSlaves()) {
                //if GerritTrigger.gerritSlaveId is configured, the selected value will be the good one because of
                //the stapler/jelly magic. The problem is when job was not saved since replication was configured,
                //we want the selected slave to be the default slave defined at admin level but I did not find a way
                //to do this. Jelly support default value returned by a descriptor method but I did not find a way to
                //pass the selected server to this method.
                //To work around the issue, we always put the default slave first in the list.
                if (slave.getId().equals(replicationConfig.getDefaultSlaveId())) {
                    items.add(0, new ListBoxModel.Option(slave.getName(), slave.getId()));
                } else {
                    items.add(slave.getName(), slave.getId());
                }
            }
View Full Code Here

            if (server == null) {
                logger.warn(Messages.CouldNotFindServer(serverName));
                items.add(Messages.CouldNotFindServer(serverName), "");
                return items;
            }
            ReplicationConfig replicationConfig = server.getConfig().getReplicationConfig();
            if (replicationConfig == null || !replicationConfig.isEnableReplication()
                || replicationConfig.getGerritSlaves().size() == 0) {
                logger.trace(Messages.GerritSlaveNotDefined());
                items.add(Messages.GerritSlaveNotDefined(), "");
                return items;
            }
            for (GerritSlave slave : replicationConfig.getGerritSlaves()) {
                boolean selected;
                if (slave.getId().equals(replicationConfig.getDefaultSlaveId())) {
                    selected = true;
                } else {
                    selected = false;
                }
                items.add(new ListBoxModel.Option(slave.getName(), slave.getId(), selected));
View Full Code Here

TOP

Related Classes of com.sonyericsson.hudson.plugins.gerrit.trigger.config.ReplicationConfig

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.