DockerCloudClientFactory implements CloudClientFactory { @Nonnull @Override public final CloudClientEx createNewClient(@Nonnull CloudState state, @Nonnull CloudClientParameters params) { Collection<String> paramNames = params.listParameterNames(); Map<String, String> properties = new HashMap<>(paramNames.size()); for (String paramName : paramNames) { properties.put(paramName, params.getParameter(paramName)); } DockerCloudClientConfig clientConfig = DockerCloudClientConfig.processParams(properties, cloudSupportRegistry); if (!clientConfig.getCloudSupport().equals(cloudSupport)) { throw new IllegalArgumentException("Cloud type mismatch, expected: " + cloudSupport + " got: " + clientConfig.getCloudSupport()); } List<DockerImageConfig> imageConfigs = DockerImageConfig.processParams(cloudSupport.createImageConfigParser(), properties, params.getCloudImages()); final int threadPoolSize = Math.min(imageConfigs.size() * 2, Runtime.getRuntime().availableProcessors() + 1); clientConfig.getDockerClientConfig() .connectionPoolSize(threadPoolSize); return new DefaultDockerCloudClient(clientConfig, imageConfigs, OfficialAgentImageResolver.forCurrentServer(DockerRegistryClientFactory.getDefault()), state, buildServer); } DockerCloudClientFactory(
            @Nonnull DockerCloudSupport cloudSupport,
            @Nonnull DockerCloudSupportRegistry cloudSupportRegistry,
            @Nonnull final SBuildServer buildServer,
            @Nonnull final PluginDescriptor pluginDescriptor); @Nonnull @Override final CloudClientEx createNewClient(@Nonnull CloudState state, @Nonnull CloudClientParameters params); @Nonnull @Override final Map<String, String> getInitialParameterValues(); @NotNull @Override String getCloudCode(); @NotNull @Override String getDisplayName(); @Nonnull @Override final String getEditProfileUrl(); @Nonnull @Override final jetbrains.buildServer.serverSide.PropertiesProcessor getPropertiesProcessor(); @Override final boolean canBeAgentOfType(@Nonnull AgentDescription description);  }
@Test public void createClient() { CloudClientParameters clientParams = new CloudClientParameters(); TestUtils.getSampleDockerConfigParams(false).forEach(clientParams::setParameter); DockerImageConfig imageConfig = DockerImageConfigBuilder. newBuilder("Test", Node.EMPTY_OBJECT). build(); CloudImageParameters imageParams = new CloudImageParameters(); imageParams.setParameter(CloudImageParameters.SOURCE_ID_FIELD, "Test"); imageParams.setParameter(CloudImageParameters.AGENT_POOL_ID_FIELD, "0"); clientParams.setParameter(CloudImageParameters.SOURCE_IMAGES_JSON, CloudImageParameters.collectionToJson(Collections.singleton(imageParams))); TestDockerImageConfigParser parser = testCloudSupport.getImageParser(); parser.addConfig(imageConfig); clientParams.setParameter(DockerCloudUtils.IMAGES_PARAM, parser.getImagesParams().toString()); DockerCloudClientFactory fty = createFactory(); imageParams.setParameter(CloudImageParameters.AGENT_POOL_ID_FIELD, "42"); Collection<CloudImageParameters> imageParamsCol = Collections.singleton(imageParams); clientParams.setCloudImages(imageParamsCol); fty.createNewClient(new TestCloudState(), clientParams); List<Collection<CloudImageParameters>> imagesParameters = parser.getImagesParametersList(); assertThat(imagesParameters).hasSize(1); assertThat(TestUtils.areImageParametersEqual(imagesParameters.get(0), imageParamsCol)).isTrue(); }