-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to configure multiple ConfigRepoUpdaters to process post MDU
- Loading branch information
Showing
9 changed files
with
186 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...n/java/com/thoughtworks/go/server/materials/ConfigMaterialPostUpdateListenersFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2019 ThoughtWorks, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.thoughtworks.go.server.materials; | ||
|
||
import com.thoughtworks.go.config.GoRepoConfigDataSource; | ||
import com.thoughtworks.go.config.materials.SubprocessExecutionContext; | ||
import com.thoughtworks.go.server.persistence.MaterialRepository; | ||
import com.thoughtworks.go.server.service.MaterialService; | ||
import com.thoughtworks.go.util.SystemEnvironment; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static java.util.stream.IntStream.range; | ||
|
||
@Component | ||
public class ConfigMaterialPostUpdateListenersFactory { | ||
private ConfigMaterialPostUpdateQueue configMaterialPostUpdateQueue; | ||
private final GoRepoConfigDataSource repoConfigDataSource; | ||
private final MaterialRepository materialRepository; | ||
private final MaterialChecker materialChecker; | ||
private final MaterialUpdateCompletedTopic materialUpdateCompletedTopic; | ||
private final MaterialService materialService; | ||
private final SubprocessExecutionContext subprocessExecutionContext; | ||
private SystemEnvironment systemEnvironment; | ||
|
||
@Autowired | ||
public ConfigMaterialPostUpdateListenersFactory(SystemEnvironment systemEnvironment, | ||
ConfigMaterialPostUpdateQueue configMaterialPostUpdateQueue, | ||
GoRepoConfigDataSource repoConfigDataSource, | ||
MaterialRepository materialRepository, | ||
MaterialChecker materialChecker, | ||
MaterialUpdateCompletedTopic materialUpdateCompletedTopic, | ||
MaterialService materialService, | ||
SubprocessExecutionContext subprocessExecutionContext) { | ||
this.systemEnvironment = systemEnvironment; | ||
this.configMaterialPostUpdateQueue = configMaterialPostUpdateQueue; | ||
this.repoConfigDataSource = repoConfigDataSource; | ||
this.materialRepository = materialRepository; | ||
this.materialChecker = materialChecker; | ||
this.materialUpdateCompletedTopic = materialUpdateCompletedTopic; | ||
this.materialService = materialService; | ||
this.subprocessExecutionContext = subprocessExecutionContext; | ||
} | ||
|
||
public void init() { | ||
int numberOfConfigMaterialPostUpdateListeners = systemEnvironment.getNumberOfConfigMaterialPostUpdateListeners(); | ||
|
||
range(0, numberOfConfigMaterialPostUpdateListeners).forEach(i -> | ||
this.configMaterialPostUpdateQueue.addListener(new ConfigMaterialUpdater(repoConfigDataSource, materialRepository, | ||
materialChecker, materialUpdateCompletedTopic, materialService, subprocessExecutionContext)) | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
server/src/main/java/com/thoughtworks/go/server/materials/ConfigMaterialPostUpdateQueue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2019 ThoughtWorks, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.thoughtworks.go.server.materials; | ||
|
||
import com.thoughtworks.go.server.messaging.GoMessageQueue; | ||
import com.thoughtworks.go.server.messaging.MessagingService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @understands messages about completed config material updates | ||
*/ | ||
@Component | ||
public class ConfigMaterialPostUpdateQueue extends GoMessageQueue<MaterialUpdateCompletedMessage> { | ||
@Autowired | ||
public ConfigMaterialPostUpdateQueue(MessagingService messaging) { | ||
super(messaging, "config-material-update-completed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...va/com/thoughtworks/go/server/materials/ConfigMaterialPostUpdateListenersFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2019 ThoughtWorks, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.thoughtworks.go.server.materials; | ||
|
||
import com.thoughtworks.go.util.SystemEnvironment; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.internal.verification.Times; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
public class ConfigMaterialPostUpdateListenersFactoryTest { | ||
@Mock | ||
private SystemEnvironment systemEnvironment; | ||
|
||
@Mock | ||
ConfigMaterialPostUpdateQueue configMaterialPostUpdateQueue; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
initMocks(this); | ||
} | ||
|
||
@Test | ||
public void shouldCreateCompetingConsumersForSuppliedDependencyMaterialQueue() { | ||
int numberOfConfigMaterialPostUpdateListeners = 3; | ||
|
||
when(systemEnvironment.getNumberOfConfigMaterialPostUpdateListeners()).thenReturn(numberOfConfigMaterialPostUpdateListeners); | ||
|
||
ConfigMaterialPostUpdateListenersFactory factory = new ConfigMaterialPostUpdateListenersFactory(systemEnvironment, configMaterialPostUpdateQueue, | ||
null, null, null, null, null, null); | ||
factory.init(); | ||
|
||
verify(configMaterialPostUpdateQueue, new Times(numberOfConfigMaterialPostUpdateListeners)).addListener(any(ConfigMaterialUpdater.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.