Skip to content

Commit 9085d9d

Browse files
authored
Add Distribution manager (#520)
1 parent f26bdfd commit 9085d9d

File tree

42 files changed

+2113
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2113
-39
lines changed

build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoExtractorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private Set<String> getArtifactSet() {
100100

101101
@BeforeClass
102102
private void setUp() throws IOException {
103-
artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setArtifactoryUrl(getUrl()).setUsername(getUsername()).setPassword(getPassword()).setLog(getLog());
103+
artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setServerUrl(getArtifactoryUrl()).setUsername(getUsername()).setPassword(getPassword()).setLog(getLog());
104104
deployTestDependencies(Project.QUOTE, Project.SAMPLER, Project.TEXT);
105105
}
106106

build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/GradlePluginTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public GradlePluginTest() {
3131

3232
// Set environment variables for variable replacement in build.gradle files
3333
envVars = new HashMap<String, String>(System.getenv()) {{
34-
putIfAbsent(BITESTS_ARTIFACTORY_ENV_VAR_PREFIX + "URL", getUrl());
35-
putIfAbsent(BITESTS_ARTIFACTORY_ENV_VAR_PREFIX + "USERNAME", getUsername());
36-
putIfAbsent(BITESTS_ARTIFACTORY_ENV_VAR_PREFIX + "PASSWORD", getPassword());
34+
putIfAbsent(BITESTS_ENV_VAR_PREFIX + "URL", getArtifactoryUrl());
35+
putIfAbsent(BITESTS_ENV_VAR_PREFIX + "USERNAME", getUsername());
36+
putIfAbsent(BITESTS_ENV_VAR_PREFIX + "PASSWORD", getPassword());
3737
putIfAbsent(BITESTS_ARTIFACTORY_ENV_VAR_PREFIX + "LOCAL_REPO", localRepo1);
3838
putIfAbsent(BITESTS_ARTIFACTORY_ENV_VAR_PREFIX + "VIRTUAL_REPO", virtualRepo);
3939
}};
@@ -85,7 +85,7 @@ public void publicationsTestKotlinDsl(String gradleVersion) throws IOException {
8585
public void ciServerTest(String gradleVersion) throws IOException {
8686
// Create test environment
8787
createTestDir(GRADLE_EXAMPLE_CI_SERVER);
88-
generateBuildInfoProperties(getUrl(), getUsername(), getPassword(), localRepo1, virtualRepo, "", true, true);
88+
generateBuildInfoProperties(getArtifactoryUrl(), getUsername(), getPassword(), localRepo1, virtualRepo, "", true, true);
8989
Map<String, String> extendedEnv = new HashMap<String, String>(envVars) {{
9090
put(BuildInfoConfigProperties.PROP_PROPS_FILE, BUILD_INFO_PROPERTIES_TARGET.toString());
9191
}};
@@ -99,7 +99,7 @@ public void ciServerTest(String gradleVersion) throws IOException {
9999
public void ciServerPublicationsTest(String gradleVersion) throws IOException {
100100
// Create test environment
101101
createTestDir(GRADLE_EXAMPLE_CI_SERVER);
102-
generateBuildInfoProperties(getUrl(), getUsername(), getPassword(), localRepo1, virtualRepo, "mavenJava,customIvyPublication", true, true);
102+
generateBuildInfoProperties(getArtifactoryUrl(), getUsername(), getPassword(), localRepo1, virtualRepo, "mavenJava,customIvyPublication", true, true);
103103
Map<String, String> extendedEnv = new HashMap<String, String>(envVars) {{
104104
put(BuildInfoConfigProperties.PROP_PROPS_FILE, BUILD_INFO_PROPERTIES_TARGET.toString());
105105
}};
@@ -113,7 +113,7 @@ public void ciServerPublicationsTest(String gradleVersion) throws IOException {
113113
public void requestedByTest(String gradleVersion) throws IOException {
114114
// Create test environment
115115
createTestDir(GRADLE_EXAMPLE_CI_SERVER);
116-
generateBuildInfoProperties(getUrl(), getUsername(), getPassword(), localRepo1, virtualRepo, "mavenJava,customIvyPublication", false, true);
116+
generateBuildInfoProperties(getArtifactoryUrl(), getUsername(), getPassword(), localRepo1, virtualRepo, "mavenJava,customIvyPublication", false, true);
117117
Map<String, String> extendedEnv = new HashMap<String, String>(envVars) {{
118118
put(BuildInfoConfigProperties.PROP_PROPS_FILE, BUILD_INFO_PROPERTIES_TARGET.toString());
119119
}};
@@ -127,7 +127,7 @@ public void requestedByTest(String gradleVersion) throws IOException {
127127
public void ciServerResolverOnlyTest(String gradleVersion) throws IOException {
128128
// Create test environment
129129
createTestDir(GRADLE_EXAMPLE_CI_SERVER);
130-
generateBuildInfoProperties(getUrl(), getUsername(), getPassword(), localRepo1, virtualRepo, "", false, false);
130+
generateBuildInfoProperties(getArtifactoryUrl(), getUsername(), getPassword(), localRepo1, virtualRepo, "", false, false);
131131
Map<String, String> extendedEnv = new HashMap<String, String>(envVars) {{
132132
put(BuildInfoConfigProperties.PROP_PROPS_FILE, BUILD_INFO_PROPERTIES_TARGET.toString());
133133
}};

build-info-extractor-npm/src/test/java/org/jfrog/build/extractor/npm/extractor/NpmExtractorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private String getTargetPath() {
115115

116116
@BeforeClass
117117
private void setUp() throws IOException {
118-
artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setArtifactoryUrl(getUrl()).setUsername(getUsername()).setPassword(getPassword()).setLog(getLog());
118+
artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setServerUrl(getArtifactoryUrl()).setUsername(getUsername()).setPassword(getPassword()).setLog(getLog());
119119
downloaderHelper = new DependenciesDownloaderHelper(artifactoryManager, ".", log);
120120
deployTestDependencies(Project.ASGARD, Project.MIDGARD, Project.ALFHEIM, Project.SVARTALFHEIM);
121121
}

build-info-extractor-nuget/src/test/java/org/jfrog/build/extractor/nuget/extractor/NugetExtractorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private enum Project {
6464

6565
@BeforeClass
6666
private void setUp() {
67-
artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setArtifactoryUrl(getUrl()).setUsername(getUsername()).setPassword(getPassword()).setLog(getLog());
67+
artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setServerUrl(getArtifactoryUrl()).setUsername(getUsername()).setPassword(getPassword()).setLog(getLog());
6868
}
6969

7070
Object[][] packagesConfigTestsInfo = new Object[][]{

build-info-extractor-pip/src/test/java/org/jfrog/build/extractor/pip/extractor/PipExtractorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private enum Project {
7777

7878
@BeforeClass
7979
private void setUp() {
80-
artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setArtifactoryUrl(getUrl()).setUsername(getUsername()).setPassword(getPassword()).setLog(getLog());
80+
artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setServerUrl(getArtifactoryUrl()).setUsername(getUsername()).setPassword(getPassword()).setLog(getLog());
8181

8282
// Read pip environment path variable.
8383
pipEnvVar = System.getenv(BITESTS_ARTIFACTORY_ENV_VAR_PREFIX + "PIP_ENV");

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactoryManagerBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ArtifactoryManagerBuilder extends ManagerBuilderBase<ArtifactoryMan
99

1010
@Override
1111
public ArtifactoryManager build() {
12-
ArtifactoryManager client = new ArtifactoryManager(artifactoryUrl, username, password, accessToken, log);
12+
ArtifactoryManager client = new ArtifactoryManager(serverUrl, username, password, accessToken, log);
1313
build(client);
1414
return client;
1515
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.jfrog.build.extractor.clientConfiguration;
2+
3+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.DistributionManager;
4+
5+
public class DistributionManagerBuilder extends ManagerBuilderBase<DistributionManagerBuilder> {
6+
7+
@Override
8+
public DistributionManager build() {
9+
DistributionManager distributionManager = new DistributionManager(serverUrl, username, password, accessToken, log);
10+
build(distributionManager);
11+
return distributionManager;
12+
}
13+
14+
@Override
15+
protected DistributionManagerBuilder self() {
16+
return this;
17+
}
18+
}

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ManagerBuilderBase.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.jfrog.build.api.util.Log;
55
import org.jfrog.build.client.ProxyConfiguration;
66
import org.jfrog.build.extractor.clientConfiguration.client.ManagerBase;
7-
import org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager;
87

98
import javax.net.ssl.SSLContext;
109
import java.io.Serializable;
@@ -19,7 +18,7 @@ public abstract class ManagerBuilderBase<T extends ManagerBuilderBase<T>> implem
1918
protected ProxyConfiguration proxyConfiguration;
2019
protected int connectionTimeout = -1;
2120
protected int connectionRetry = -1;
22-
protected String artifactoryUrl;
21+
protected String serverUrl;
2322
protected SSLContext sslContext;
2423
protected String username;
2524
protected String password;
@@ -41,8 +40,8 @@ public T setConnectionRetry(int connectionRetry) {
4140
return self();
4241
}
4342

44-
public T setArtifactoryUrl(String artifactoryUrl) {
45-
this.artifactoryUrl = artifactoryUrl;
43+
public T setServerUrl(String serverUrl) {
44+
this.serverUrl = serverUrl;
4645
return self();
4746
}
4847

@@ -80,7 +79,7 @@ public T setLog(Log log) {
8079
*/
8180
public T setClientConfiguration(ArtifactoryClientConfiguration clientConfiguration,
8281
ArtifactoryClientConfiguration.RepositoryConfiguration repositoryConfiguration) {
83-
setArtifactoryUrl(repositoryConfiguration.getContextUrl());
82+
setServerUrl(repositoryConfiguration.getContextUrl());
8483
setUsername(repositoryConfiguration.getUsername());
8584
setPassword(repositoryConfiguration.getPassword());
8685
setLog(repositoryConfiguration.getLog());
@@ -106,7 +105,7 @@ public T setClientConfiguration(ArtifactoryClientConfiguration clientConfigurati
106105
return self();
107106
}
108107

109-
protected ArtifactoryManager build(ArtifactoryManager client) {
108+
protected ManagerBase build(ManagerBase client) {
110109
if (proxyConfiguration != null) {
111110
client.setProxyConfiguration(proxyConfiguration.host,
112111
proxyConfiguration.port,

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/ManagerBase.java

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.jfrog.build.client.ProxyConfiguration;
77

88
import javax.net.ssl.SSLContext;
9+
import java.io.IOException;
910

1011
public abstract class ManagerBase implements AutoCloseable {
1112
protected final JFrogHttpClient jfrogHttpClient;
@@ -20,6 +21,8 @@ protected ManagerBase(String url, String username, String password, String acces
2021
log = logger;
2122
}
2223

24+
public abstract org.jfrog.build.client.Version getVersion() throws IOException;
25+
2326
/**
2427
* Network timeout in seconds to use both for connection establishment and for unanswered requests.
2528
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package org.jfrog.build.extractor.clientConfiguration.client.distribution;
2+
3+
import org.apache.commons.lang.StringUtils;
4+
import org.jfrog.build.api.util.Log;
5+
import org.jfrog.build.extractor.clientConfiguration.client.ManagerBase;
6+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.request.CreateReleaseBundleRequest;
7+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.request.DeleteReleaseBundleRequest;
8+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.request.DistributeReleaseBundleRequest;
9+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.request.UpdateReleaseBundleRequest;
10+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.response.DistributeReleaseBundleResponse;
11+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.response.DistributionStatusResponse;
12+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.response.GetReleaseBundleStatusResponse;
13+
import org.jfrog.build.extractor.clientConfiguration.client.distribution.services.*;
14+
15+
import java.io.IOException;
16+
17+
/**
18+
* @author yahavi
19+
*/
20+
@SuppressWarnings("unused")
21+
public class DistributionManager extends ManagerBase {
22+
public DistributionManager(String url, String username, String password, String accessToken, Log logger) {
23+
super(url, username, password, accessToken, logger);
24+
}
25+
26+
public DistributionManager(String url, String username, String password, Log log) {
27+
super(url, username, password, StringUtils.EMPTY, log);
28+
}
29+
30+
public DistributionManager(String url, String accessToken, Log log) {
31+
super(url, StringUtils.EMPTY, StringUtils.EMPTY, accessToken, log);
32+
}
33+
34+
public DistributionManager(String url, Log log) {
35+
super(url, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, log);
36+
}
37+
38+
/**
39+
* Get version of JFrog distribution.
40+
*
41+
* @return version of JFrog distribution
42+
* @throws IOException in case of any error
43+
*/
44+
public org.jfrog.build.client.Version getVersion() throws IOException {
45+
Version versionService = new Version(log);
46+
return versionService.execute(jfrogHttpClient);
47+
}
48+
49+
/**
50+
* Create a release bundle.
51+
*
52+
* @param request - The release bundle details
53+
* @param gpgPassphrase - GPG passphrase
54+
* @throws IOException in case of any error
55+
*/
56+
public void createReleaseBundle(CreateReleaseBundleRequest request, String gpgPassphrase) throws IOException {
57+
new CreateReleaseBundle(request, gpgPassphrase, log).execute(jfrogHttpClient);
58+
}
59+
60+
/**
61+
* Create a release bundle.
62+
*
63+
* @param request - The release bundle details
64+
* @throws IOException in case of any error
65+
*/
66+
public void createReleaseBundle(CreateReleaseBundleRequest request) throws IOException {
67+
createReleaseBundle(request, "");
68+
}
69+
70+
/**
71+
* Update a release bundle.
72+
*
73+
* @param request - The release bundle details
74+
* @param gpgPassphrase - GPG passphrase
75+
* @throws IOException in case of any error
76+
*/
77+
public void updateReleaseBundle(String name, String version, UpdateReleaseBundleRequest request, String gpgPassphrase) throws IOException {
78+
new UpdateReleaseBundle(request, name, version, gpgPassphrase, log).execute(jfrogHttpClient);
79+
}
80+
81+
/**
82+
* Update a release bundle.
83+
*
84+
* @param request - The release bundle details
85+
* @throws IOException in case of any error
86+
*/
87+
public void updateReleaseBundle(String name, String version, UpdateReleaseBundleRequest request) throws IOException {
88+
updateReleaseBundle(name, version, request, "");
89+
}
90+
91+
/**
92+
* Sign a release bundle
93+
*
94+
* @param name - Release bundle name to sign
95+
* @param version - Release bundle version to sign
96+
* @param gpgPassphrase - GPG passphrase
97+
* @param storingRepository - The storing repository
98+
* @throws IOException in case of any error
99+
*/
100+
public void signReleaseBundle(String name, String version, String gpgPassphrase, String storingRepository) throws IOException {
101+
new SignReleaseBundle(name, version, gpgPassphrase, storingRepository, log).execute(jfrogHttpClient);
102+
}
103+
104+
/**
105+
* Sign a release bundle
106+
*
107+
* @param name - Release bundle name to sign
108+
* @param version - Release bundle version to sign
109+
* @param gpgPassphrase - GPG passphrase
110+
* @throws IOException in case of any error
111+
*/
112+
public void signReleaseBundle(String name, String version, String gpgPassphrase) throws IOException {
113+
signReleaseBundle(name, version, gpgPassphrase, "");
114+
}
115+
116+
/**
117+
* Get release bundle status.
118+
*
119+
* @param name - Release bundle name
120+
* @param version - Release bundle version
121+
* @return release bundle status
122+
* @throws IOException in case of any error
123+
*/
124+
public GetReleaseBundleStatusResponse getReleaseBundleStatus(String name, String version) throws IOException {
125+
return new GetReleaseBundleVersion(name, version, log).execute(jfrogHttpClient);
126+
}
127+
128+
/**
129+
* Distribute a release bundle.
130+
*
131+
* @param name - Release bundle name
132+
* @param version - Release bundle version
133+
* @param sync - Set to true to enable sync distribution
134+
* @param request - The distribution details
135+
* @return the tracker id and sites details
136+
* @throws IOException in case of any error
137+
*/
138+
public DistributeReleaseBundleResponse distributeReleaseBundle(String name, String version, boolean sync, DistributeReleaseBundleRequest request) throws IOException {
139+
return new DistributeReleaseBundle(name, version, sync, request, log).execute(jfrogHttpClient);
140+
}
141+
142+
/**
143+
* Get status of a distributed release bundle
144+
*
145+
* @param name - Release bundle name
146+
* @param version - Release bundle version
147+
* @return status of a distributed release bundle
148+
* @throws IOException in case of any error
149+
*/
150+
public DistributionStatusResponse getDistributionStatus(String name, String version) throws IOException {
151+
return new GetDistributionStatus(name, version, "", log).execute(jfrogHttpClient);
152+
}
153+
154+
/**
155+
* Get status of a distributed release bundle
156+
*
157+
* @param name - Release bundle name
158+
* @param version - Release bundle version
159+
* @param trackerId - The tracker ID received from distributeReleaseBundle command
160+
* @return status of a distributed release bundle
161+
* @throws IOException in case of any error
162+
*/
163+
public DistributionStatusResponse getDistributionStatus(String name, String version, String trackerId) throws IOException {
164+
return new GetDistributionStatus(name, version, trackerId, log).execute(jfrogHttpClient);
165+
}
166+
167+
/**
168+
* Delete a release bundle from local Artifactory
169+
*
170+
* @param name - Release bundle name
171+
* @param version - Release bundle version
172+
* @throws IOException in case of any error
173+
*/
174+
public void deleteLocalReleaseBundle(String name, String version) throws IOException {
175+
new DeleteLocalReleaseBundle(name, version, log).execute(jfrogHttpClient);
176+
}
177+
178+
/**
179+
* Delete a release bundle from edge node, and optionally from the local Artifactory.
180+
*
181+
* @param name - Release bundle name
182+
* @param version - Release bundle version
183+
* @param sync - Set to true to enable sync deletion
184+
* @param request - The distribution details
185+
* @return sites details
186+
* @throws IOException in case of any error
187+
*/
188+
public DistributeReleaseBundleResponse deleteReleaseBundle(String name, String version, boolean sync, DeleteReleaseBundleRequest request) throws IOException {
189+
return new DeleteReleaseBundle(name, version, sync, request, log).execute(jfrogHttpClient);
190+
}
191+
}

0 commit comments

Comments
 (0)