jetbrains.buildServer.util.CollectionsUtil Java Examples
The following examples show how to use
jetbrains.buildServer.util.CollectionsUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractPodTemplateProvider.java From teamcity-kubernetes-plugin with Apache License 2.0 | 6 votes |
private void patchMetadata(@NotNull final String instanceName, @NotNull final String namespace, @NotNull final String serverUUID, @NotNull final String imageId, @NotNull final CloudInstanceUserData cloudInstanceUserData, @NotNull final ObjectMeta metadata) { metadata.setName(instanceName); metadata.setNamespace(namespace); Map<String, String> patchedLabels = new HashMap<>(); if (metadata.getLabels() != null) { patchedLabels.putAll(metadata.getLabels()); } patchedLabels.putAll(CollectionsUtil.asMap( KubeTeamCityLabels.TEAMCITY_AGENT_LABEL, "", KubeTeamCityLabels.TEAMCITY_SERVER_UUID, serverUUID, KubeTeamCityLabels.TEAMCITY_CLOUD_PROFILE, cloudInstanceUserData.getProfileId(), KubeTeamCityLabels.TEAMCITY_CLOUD_IMAGE, imageId)); metadata.setLabels(patchedLabels); }
Example #2
Source File: SmbDeployerRunner.java From teamcity-deployer-plugin with Apache License 2.0 | 6 votes |
@NotNull private ClassLoader loadClassesFrom(String libDirectory) { final File[] files = new File(root, libDirectory).listFiles(); final URL[] urls = CollectionsUtil.convertCollection(Arrays.asList(files), new Converter<URL, File>() { @Override public URL createFrom(@NotNull File file) { try { return file.toURI().toURL(); } catch (Exception e) { throw new RuntimeException(e); } } }).toArray(new URL[files.length]); return new URLClassLoader(urls, getClass().getClassLoader()); }
Example #3
Source File: KubeCloudClientFactory.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@NotNull @Override public CloudClientEx createNewClient(@NotNull CloudState cloudState, @NotNull CloudClientParameters cloudClientParameters) { try { final KubeCloudClientParametersImpl kubeClientParams = KubeCloudClientParametersImpl.create(cloudClientParameters); final ExecutorService executorService = ExecutorsFactory.newFixedScheduledDaemonExecutor("Async cloud tasks for " + cloudState.getProfileId(), 2); final KubeApiConnector apiConnector = new KubeApiConnectorImpl(cloudClientParameters.getProfileId(), kubeClientParams, myAuthStrategies.get(kubeClientParams.getAuthStrategy())); List<KubeCloudImage> images = CollectionsUtil.convertCollection(kubeClientParams.getImages(), kubeCloudImageData -> { final KubeCloudImageImpl kubeCloudImage = new KubeCloudImageImpl(kubeCloudImageData, apiConnector); kubeCloudImage.populateInstances(); return kubeCloudImage; }); return new KubeCloudClient( apiConnector, myServerSettings.getServerUUID(), cloudState.getProfileId(), images, kubeClientParams, myUpdater, myPodTemplateProviders, executorService, myKubePodNameGenerator ); } catch (Throwable ex){ if(ex instanceof KubernetesClientException){ final Throwable cause = ex.getCause(); if(cause != null) throw new CloudException(cause.getMessage(), cause); else throw ex; } else throw ex; } }
Example #4
Source File: KubeApiConnectorImpl.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@NotNull @Override public Collection<String> listNamespaces() { return withKubernetesClient(kubernetesClient -> { return CollectionsUtil.convertCollection(kubernetesClient.namespaces().list().getItems(), namespace -> namespace.getMetadata().getName()); }); }
Example #5
Source File: KubeApiConnectorImpl.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@NotNull @Override public Collection<String> listDeployments() { return withKubernetesClient(kubernetesClient -> { return CollectionsUtil.convertCollection(kubernetesClient.apps().deployments().list().getItems(), namespace -> namespace.getMetadata().getName()); }); }
Example #6
Source File: DeploymentBuildAgentPodTemplateProviderTest.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
public void testGetPodTemplate() throws Exception { CloudInstanceUserData instanceTag = createInstanceTag(); KubeCloudClientParameters clientParams = m.mock(KubeCloudClientParameters.class); KubeCloudImage image = m.mock(KubeCloudImage.class); Deployment deployment = new DeploymentBuilder() .withMetadata(new ObjectMetaBuilder() .withLabels(CollectionsUtil.asMap("app", "nginx")) .build()) .withSpec(new DeploymentSpecBuilder() .withTemplate(new PodTemplateSpecBuilder() .withMetadata(new ObjectMeta()) .withSpec(new PodSpecBuilder() .withContainers(new ContainerBuilder() .withName("nginx") .withImage("nginx:1.7.9") .withPorts(new ContainerPortBuilder() .withHostPort(80) .build()) .build()) .build()) .build()) .build()) .build(); m.checking(new Expectations(){{ allowing(clientParams).getNamespace(); will(returnValue("custom namespace")); allowing(clientParams).getAuthStrategy(); will(returnValue(UnauthorizedAccessStrategy.ID)); allowing(image).getId(); will(returnValue("my image id")); allowing(image).getName(); will(returnValue("my image name")); allowing(image).getSourceDeploymentName(); will(returnValue("deploymentFoo")); allowing(image).getAgentNamePrefix(); will(returnValue("agent-name-prefix")); allowing(image).findInstanceById(with("agent-name-prefix-1")); will(returnValue(null)); allowing(image).getAgentName(with("agent name")); will(returnValue("prefix agent name")); allowing(myDeploymentContentProvider).findDeployment(with(any(String.class)), with(any(KubeCloudClientParameters.class))); will(returnValue(deployment)); }}); Pod podTemplate = myPodTemplateProvider.getPodTemplate(myNameGenerator.generateNewVmName(image), instanceTag, image, clientParams); assertNotNull(podTemplate); assertNotNull(podTemplate.getMetadata()); assertNotNull(podTemplate.getSpec()); }
Example #7
Source File: DeploymentBuildAgentPodTemplateProviderTest.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
public void testShouldNotsetContainerName(){ CloudInstanceUserData instanceTag = createInstanceTag(); KubeCloudClientParameters clientParams = m.mock(KubeCloudClientParameters.class); KubeCloudImage image = m.mock(KubeCloudImage.class); Deployment deployment = new DeploymentBuilder() .withMetadata(new ObjectMetaBuilder() .withLabels(CollectionsUtil.asMap("app", "nginx")) .build()) .withSpec(new DeploymentSpecBuilder() .withTemplate(new PodTemplateSpecBuilder() .withMetadata(new ObjectMeta()) .withSpec(new PodSpecBuilder() .withContainers(new ContainerBuilder() .withName("nginx") .withImage("nginx:1.7.9") .withPorts(new ContainerPortBuilder() .withHostPort(80) .build()) .build()) .build()) .build()) .build()) .build(); m.checking(new Expectations(){{ allowing(clientParams).getNamespace(); will(returnValue("custom namespace")); allowing(image).getId(); will(returnValue("my image id")); allowing(image).getName(); will(returnValue("my image name")); allowing(image).getAgentNamePrefix(); will(returnValue("agent-name-prefix")); allowing(image).findInstanceById(with("agent-name-prefix-1")); will(returnValue(null)); allowing(image).getSourceDeploymentName(); will(returnValue("deploymentFoo")); allowing(image).getAgentName(with("agent name")); will(returnValue("prefix agent name")); allowing(myDeploymentContentProvider).findDeployment(with(any(String.class)), with(any(KubeCloudClientParameters.class))); will(returnValue(deployment)); }}); Pod podTemplate = myPodTemplateProvider.getPodTemplate(myNameGenerator.generateNewVmName(image), instanceTag, image, clientParams); for(Container container : podTemplate.getSpec().getContainers()){ assertNotSame(container.getName(), "agent name"); } }
Example #8
Source File: S3ArtifactsPublisher.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 5 votes |
@Override public int publishFiles(@NotNull final Map<File, String> map) throws ArtifactPublishingFailedException { final Map<File, String> filteredMap = CollectionsUtil.filterMapByValues(map, s -> !s.startsWith(ArtifactsConstants.TEAMCITY_ARTIFACTS_DIR)); if (!filteredMap.isEmpty()) { final AgentRunningBuild build = myTracker.getCurrentBuild(); final String pathPrefix = getPathPrefix(build); final S3FileUploader fileUploader = getFileUploader(build); myArtifacts.addAll(fileUploader.publishFiles(build, pathPrefix, filteredMap)); publishArtifactsList(build); } return filteredMap.size(); }
Example #9
Source File: S3ArtifactsPublisher.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 5 votes |
private void publishArtifactsList(@NotNull final AgentRunningBuild build) { if (!myArtifacts.isEmpty()) { final String pathPrefix = getPathPrefix(build); try { myHelper.publishArtifactList(myArtifacts, CollectionsUtil.asMap(S3_PATH_PREFIX_ATTR, pathPrefix)); } catch (IOException e) { build.getBuildLogger().error(ERROR_PUBLISHING_ARTIFACTS_LIST + ": " + e.getMessage()); LOG.warnAndDebugDetails(ERROR_PUBLISHING_ARTIFACTS_LIST + "for build " + LogUtil.describe(build), e); } } }
Example #10
Source File: JetSymbolsExe.java From teamcity-symbol-server with Apache License 2.0 | 5 votes |
public Collection<File> getReferencedSourceFiles(File symbolsFile, BuildProgressLogger buildLogger) { final GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(myExePath.getPath()); commandLine.addParameter(LIST_SOURCES_CMD); commandLine.addParameter(symbolsFile.getAbsolutePath()); final ExecResult execResult = executeCommandLine(commandLine, buildLogger); if (execResult.getExitCode() == 0) { return CollectionsUtil.convertAndFilterNulls(Arrays.asList(execResult.getOutLines()), File::new); } else { return Collections.emptyList(); } }
Example #11
Source File: AllureToolProvider.java From allure-teamcity with Apache License 2.0 | 5 votes |
@NotNull @Override public File fetchToolPackage(@NotNull ToolVersion toolVersion, @NotNull File targetDirectory) throws ToolException { String id = toolVersion.getId(); DownloadableToolVersion tool = CollectionsUtil.findFirst(fetcher.fetchAvailable().getFetchedTools(), data -> data.getId().equals(id)); if (tool == null) { throw new ToolException("Failed to fetch allure-commandline tool " + toolVersion + "."); } File allureCommandLine = new File(tool.getDestinationFileName()); URLDownloader.download(tool.getDownloadUrl(), allureCommandLine); return allureCommandLine; }
Example #12
Source File: KubeCloudClientParametersImpl.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
@NotNull @Override public Collection<KubeCloudImageData> getImages(){ return CollectionsUtil.convertCollection(myParameters.getCloudImages(), KubeCloudImageData::new); }
Example #13
Source File: SimpleRunContainerProvider.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
@NotNull @Override public Pod getPodTemplate(@NotNull String instanceName, @NotNull CloudInstanceUserData cloudInstanceUserData, @NotNull KubeCloudImage kubeCloudImage, @NotNull KubeCloudClientParameters clientParameters) { ImagePullPolicy imagePullPolicy = kubeCloudImage.getImagePullPolicy(); String serverAddress = cloudInstanceUserData.getServerAddress(); String serverUUID = myServerSettings.getServerUUID(); String cloudProfileId = cloudInstanceUserData.getProfileId(); ContainerBuilder containerBuilder = new ContainerBuilder() .withName(instanceName) .withImage(kubeCloudImage.getDockerImage()) .withImagePullPolicy(imagePullPolicy == null ? ImagePullPolicy.IfNotPresent.getName() : imagePullPolicy.getName()) .withEnv(new EnvVar(KubeContainerEnvironment.SERVER_URL, serverAddress, null), new EnvVar(KubeContainerEnvironment.SERVER_UUID, serverUUID, null), new EnvVar(KubeContainerEnvironment.OFFICIAL_IMAGE_SERVER_URL, serverAddress, null), new EnvVar(KubeContainerEnvironment.IMAGE_NAME, kubeCloudImage.getId(), null), new EnvVar(KubeContainerEnvironment.PROFILE_ID, cloudProfileId, null), new EnvVar(KubeContainerEnvironment.INSTANCE_NAME, instanceName, null)); String dockerCommand = kubeCloudImage.getDockerCommand(); if(!StringUtil.isEmpty(dockerCommand)) containerBuilder = containerBuilder.withCommand(dockerCommand); String dockerArguments = kubeCloudImage.getDockerArguments(); if(!StringUtil.isEmpty(dockerArguments)) containerBuilder = containerBuilder.withArgs(dockerArguments); return new PodBuilder() .withNewMetadata() .withName(instanceName) .withNamespace(clientParameters.getNamespace()) .withLabels(CollectionsUtil.asMap( KubeTeamCityLabels.TEAMCITY_AGENT_LABEL, "", KubeTeamCityLabels.TEAMCITY_SERVER_UUID, serverUUID, KubeTeamCityLabels.TEAMCITY_CLOUD_PROFILE, cloudProfileId, KubeTeamCityLabels.TEAMCITY_CLOUD_IMAGE, kubeCloudImage.getId())) .endMetadata() .withNewSpec() .withContainers(Collections.singletonList(containerBuilder.build())) .withRestartPolicy(KubeApiConnector.NEVER_RESTART_POLICY) .endSpec() .build(); }
Example #14
Source File: DeploymentBuildAgentPodTemplateProviderTest.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
public void testDoNotLoseSpecAdditionalProperties() throws Exception { CloudInstanceUserData instanceTag = createInstanceTag(); KubeCloudClientParameters clientParams = m.mock(KubeCloudClientParameters.class); KubeCloudImage image = m.mock(KubeCloudImage.class); Deployment deployment = new DeploymentBuilder() .withMetadata(new ObjectMetaBuilder() .withLabels(CollectionsUtil.asMap("app", "nginx")) .build()) .withSpec(new DeploymentSpecBuilder() .withTemplate(new PodTemplateSpecBuilder() .withMetadata(new ObjectMeta()) .withSpec(new PodSpecBuilder() .withContainers(new ContainerBuilder() .withName("nginx") .withImage("nginx:1.7.9") .withPorts(new ContainerPortBuilder() .withHostPort(80) .build()) .build()) .build()) .build()) .build()) .build(); deployment.getSpec().getTemplate().getSpec().setAdditionalProperty("affinity", "some value"); m.checking(new Expectations(){{ allowing(clientParams).getNamespace(); will(returnValue("custom namespace")); allowing(image).getId(); will(returnValue("my image id")); allowing(image).getName(); will(returnValue("my image name")); allowing(image).getAgentNamePrefix(); will(returnValue("agent-name-prefix")); allowing(image).findInstanceById(with("agent-name-prefix-1")); will(returnValue(null)); allowing(image).getSourceDeploymentName(); will(returnValue("deploymentFoo")); allowing(image).getAgentName(with("agent name")); will(returnValue("prefix agent name")); allowing(myDeploymentContentProvider).findDeployment(with(any(String.class)), with(any(KubeCloudClientParameters.class))); will(returnValue(deployment)); }}); Pod podTemplate = myPodTemplateProvider.getPodTemplate(myNameGenerator.generateNewVmName(image), instanceTag, image, clientParams); assertNotEmpty(podTemplate.getSpec().getAdditionalProperties().keySet()); }