Skip to content

Commit 7f89f31

Browse files
authored
mgmt appplatform support enterprise tier deployment (Azure#28439)
* support enterprise tier deployment * source code deployment remove redundant deployment activation nit, comments * deployment config file patterns * changelog * session records * nit, comment * nit, change config repository uri * add configuration service binding to customer service * support cpu and memory in string * nit * nit, javadoc and renaming * new waitforbuild pattern * add timeout * add buildId to error log
1 parent 43363db commit 7f89f31

File tree

10 files changed

+4632
-13330
lines changed

10 files changed

+4632
-13330
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/piggymetrics.tar.gz
2+
/petclinic.tar.gz
23
# folder created in unit test

sdk/resourcemanager/azure-resourcemanager-appplatform/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Supported Enterprise Tier `Configuration Service`.
88
- Supported Enterprise Tier `Build Service`.
99
- Supported Enterprise Tier binding `Spring App` to `Configuration Service`.
10+
- Supported Enterprise Tier `Spring App Deployment` with `Jar` and `Maven Source Code`.
1011

1112
### Breaking Changes
1213

sdk/resourcemanager/azure-resourcemanager-appplatform/src/main/java/com/azure/resourcemanager/appplatform/implementation/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class Constants {
88
public static final String DEFAULT_TANZU_COMPONENT_NAME = "default";
99
public static final String APPLICATION_CONFIGURATION_SERVICE_KEY = "applicationConfigurationService";
1010
public static final String BINDING_RESOURCE_ID = "resourceId";
11+
public static final String CONFIG_FILE_PATTERNS_KEY = "configFilePatterns";
1112
}

sdk/resourcemanager/azure-resourcemanager-appplatform/src/main/java/com/azure/resourcemanager/appplatform/implementation/SpringAppDeploymentImpl.java

Lines changed: 313 additions & 59 deletions
Large diffs are not rendered by default.

sdk/resourcemanager/azure-resourcemanager-appplatform/src/main/java/com/azure/resourcemanager/appplatform/models/SpringAppDeployment.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public interface SpringAppDeployment
7070
/** @return the log file url of the deployment */
7171
Mono<String> getLogFileUrlAsync();
7272

73+
/** @return (Enterprise Tier Only) config file patterns */
74+
List<String> configFilePatterns();
75+
7376
/**
7477
* Container interface for all the definitions that need to be implemented.
7578
* @param <ParentT> the stage of the parent definition to return to after attaching this definition
@@ -97,6 +100,18 @@ interface WithSource<T> {
97100
*/
98101
T withJarFile(File jar);
99102

103+
/**
104+
* (Enterprise Tier Only)
105+
* Specifies the jar package for the deployment.
106+
* @param jar the file of the jar
107+
* @param configFilePatterns config file patterns to decide which patterns of Application Configuration Service will be used
108+
* (App has to have a binding to the Configuration Service first in order to read the config files
109+
* {@link com.azure.resourcemanager.appplatform.models.SpringApp.DefinitionStages.WithConfigurationServiceBinding}),
110+
* use null or empty list to clear existing configurations
111+
* @return the next stage of deployment definition
112+
*/
113+
T withJarFile(File jar, List<String> configFilePatterns);
114+
100115
// Remove compression first due to tar.gz needs extern dependency
101116
// /**
102117
// * Specifies the source code for the deployment.
@@ -112,6 +127,18 @@ interface WithSource<T> {
112127
*/
113128
WithModule<T> withSourceCodeTarGzFile(File sourceCodeTarGz);
114129

130+
/**
131+
* (Enterprise Tier Only)
132+
* Specifies the source code for the deployment.
133+
* @param sourceCodeTarGz a tar.gz file of the source code
134+
* @param configFilePatterns config file patterns to decide which patterns of Application Configuration Service will be used
135+
* (App has to have a binding to the Configuration Service first in order to read the config files
136+
* {@link com.azure.resourcemanager.appplatform.models.SpringApp.DefinitionStages.WithConfigurationServiceBinding}),
137+
* use null or empty list to clear existing configurations.
138+
* @return the next stage of deployment definition
139+
*/
140+
WithModule<T> withSourceCodeTarGzFile(File sourceCodeTarGz, List<String> configFilePatterns);
141+
115142
/**
116143
* Specifies the a existing source in the cloud storage.
117144
* @param type the source type in previous upload
@@ -153,13 +180,27 @@ interface WithSettings<T> {
153180
*/
154181
T withCpu(int cpuCount);
155182

183+
/**
184+
* Specifies the cpu number of the deployment.
185+
* @param cpuCount the number of the cpu, 1 core can be represented by 1 or 1000m
186+
* @return the next stage of deployment definition
187+
*/
188+
T withCpu(String cpuCount);
189+
156190
/**
157191
* Specifies the memory of the deployment.
158192
* @param sizeInGB the size of the memory in GB
159193
* @return the next stage of deployment definition
160194
*/
161195
T withMemory(int sizeInGB);
162196

197+
/**
198+
* Specifies the memory of the deployment.
199+
* @param size the size of the memory, 1 GB can be represented by 1Gi or 1024Mi
200+
* @return the next stage of deployment definition
201+
*/
202+
T withMemory(String size);
203+
163204
/**
164205
* Specifies the runtime version of the deployment.
165206
* @param version the runtime version of Java
@@ -194,6 +235,14 @@ interface WithSettings<T> {
194235
* @return the next stage of deployment definition
195236
*/
196237
T withActivation();
238+
239+
/**
240+
* Specifies the config file patterns for the deployment.
241+
* @param configFilePatterns Config file patterns to decide which patterns of Application Configuration Service will be used.
242+
* Use null or empty list to clear existing configurations.
243+
* @return the next stage of deployment definition
244+
*/
245+
T withConfigFilePatterns(List<String> configFilePatterns);
197246
}
198247

199248
/**
@@ -237,13 +286,27 @@ interface WithSettings {
237286
*/
238287
Update withCpu(int cpuCount);
239288

289+
/**
290+
* Specifies the cpu number of the deployment.
291+
* @param cpuCount the number of the cpu, 1 core can be represented by 1 or 1000m
292+
* @return the next stage of deployment update
293+
*/
294+
Update withCpu(String cpuCount);
295+
240296
/**
241297
* Specifies the memory of the deployment.
242298
* @param sizeInGB the size of the memory in GB
243299
* @return the next stage of deployment update
244300
*/
245301
Update withMemory(int sizeInGB);
246302

303+
/**
304+
* Specifies the memory of the deployment.
305+
* @param size the size of the memory, 1 GB can be represented by 1Gi or 1024Mi
306+
* @return the next stage of deployment update
307+
*/
308+
Update withMemory(String size);
309+
247310
/**
248311
* Specifies the runtime version of the deployment.
249312
* @param version the runtime version of Java
@@ -285,6 +348,14 @@ interface WithSettings {
285348
* @return the next stage of deployment update
286349
*/
287350
Update withActivation();
351+
352+
/**
353+
* Specifies the config file patterns for the deployment.
354+
* @param configFilePatterns Config file patterns to decide which patterns of Application Configuration Service will be used.
355+
* Use null or empty list to clear existing configurations.
356+
* @return the next stage of deployment update
357+
*/
358+
Update withConfigFilePatterns(List<String> configFilePatterns);
288359
}
289360

290361
/** The stage of a deployment update allowing to specify the source code or package. */
@@ -296,6 +367,18 @@ interface WithSource {
296367
*/
297368
Update withJarFile(File jar);
298369

370+
/**
371+
* (Enterprise Tier Only)
372+
* Specifies the jar package for the deployment.
373+
* @param jar the file of the jar
374+
* @param configFilePatterns config file patterns to decide which patterns of Application Configuration Service will be used
375+
* (App has to have a binding to the Configuration Service first in order to read the config files
376+
* {@link com.azure.resourcemanager.appplatform.models.SpringApp.DefinitionStages.WithConfigurationServiceBinding})
377+
* use null or empty list to clear existing configurations
378+
* @return the next stage of deployment update
379+
*/
380+
Update withJarFile(File jar, List<String> configFilePatterns);
381+
299382
// /**
300383
// * Specifies the source code for the deployment.
301384
// * @param sourceCodeFolder the folder of the source code
@@ -310,6 +393,18 @@ interface WithSource {
310393
*/
311394
WithModule withSourceCodeTarGzFile(File sourceCodeTarGz);
312395

396+
/**
397+
* (Enterprise Tier Only)
398+
* Specifies the source code for the deployment.
399+
* @param sourceCodeTarGz a tar.gz file of the source code
400+
* @param configFilePatterns config file patterns to decide which patterns of Application Configuration Service will be used
401+
* (App has to have a binding to the Configuration Service first in order to read the config files
402+
* {@link com.azure.resourcemanager.appplatform.models.SpringApp.DefinitionStages.WithConfigurationServiceBinding})
403+
* use null or empty list to clear existing configurations.
404+
* @return the next stage of deployment update
405+
*/
406+
WithModule withSourceCodeTarGzFile(File sourceCodeTarGz, List<String> configFilePatterns);
407+
313408
/**
314409
* Specifies the a existing source in the cloud storage.
315410
* @param type the source type in previous upload

sdk/resourcemanager/azure-resourcemanager-appplatform/src/test/java/com/azure/resourcemanager/appplatform/SpringCloudLiveOnlyTest.java

Lines changed: 91 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.azure.core.management.Region;
77
import com.azure.core.test.annotation.DoNotRecord;
8+
import com.azure.core.util.CoreUtils;
89
import com.azure.resourcemanager.appplatform.models.RuntimeVersion;
910
import com.azure.resourcemanager.appplatform.models.SpringApp;
1011
import com.azure.resourcemanager.appplatform.models.SpringAppDeployment;
@@ -51,16 +52,15 @@ public class SpringCloudLiveOnlyTest extends AppPlatformTest {
5152
private static final String PIGGYMETRICS_CONFIG_URL = "https://github.com/Azure-Samples/piggymetrics-config";
5253
private static final String GATEWAY_JAR_URL = "https://github.com/weidongxu-microsoft/azure-sdk-for-java-management-tests/raw/master/spring-cloud/gateway.jar";
5354
private static final String PIGGYMETRICS_TAR_GZ_URL = "https://github.com/weidongxu-microsoft/azure-sdk-for-java-management-tests/raw/master/spring-cloud/piggymetrics.tar.gz";
55+
private static final String PETCLINIC_CONFIG_URL = "https://github.com/XiaofeiCao/spring-petclinic-microservices-config";
56+
private static final String PETCLINIC_GATEWAY_JAR_URL = "https://github.com/weidongxu-microsoft/azure-sdk-for-java-management-tests/tree/master/spring-cloud/api-gateway.jar";
57+
private static final String PETCLINIC_TAR_GZ_URL = "https://github.com/weidongxu-microsoft/azure-sdk-for-java-management-tests/tree/master/spring-cloud/petclinic.tar.gz";
5458

5559
private static final String SPRING_CLOUD_SERVICE_OBJECT_ID = "938df8e2-2b9d-40b1-940c-c75c33494239";
5660

5761
@Test
58-
@DoNotRecord
62+
@DoNotRecord(skipInPlayback = true)
5963
public void canCRUDDeployment() throws Exception {
60-
if (skipInPlayback()) {
61-
return;
62-
}
63-
6464
allowAllSSL();
6565

6666
String serviceName = generateRandomResourceName("springsvc", 15);
@@ -74,16 +74,7 @@ public void canCRUDDeployment() throws Exception {
7474
.withNewResourceGroup(rgName)
7575
.create();
7676

77-
File jarFile = new File("gateway.jar");
78-
if (!jarFile.exists()) {
79-
HttpURLConnection connection = (HttpURLConnection) new URL(GATEWAY_JAR_URL).openConnection();
80-
connection.connect();
81-
try (InputStream inputStream = connection.getInputStream();
82-
OutputStream outputStream = new FileOutputStream(jarFile)) {
83-
IOUtils.copy(inputStream, outputStream);
84-
}
85-
connection.disconnect();
86-
}
77+
File jarFile = downloadFile(GATEWAY_JAR_URL);
8778

8879
SpringApp app = service.apps().define(appName)
8980
.defineActiveDeployment(deploymentName)
@@ -109,17 +100,7 @@ public void canCRUDDeployment() throws Exception {
109100
// Assertions.assertEquals(RuntimeVersion.JAVA_11, deployment.settings().runtimeVersion());
110101
Assertions.assertEquals(2, deployment.instances().size());
111102

112-
File gzFile = new File("piggymetrics.tar.gz");
113-
if (!gzFile.exists()) {
114-
allowAllSSL();
115-
HttpURLConnection connection = (HttpURLConnection) new URL(PIGGYMETRICS_TAR_GZ_URL).openConnection();
116-
connection.connect();
117-
try (InputStream inputStream = connection.getInputStream();
118-
OutputStream outputStream = new FileOutputStream(gzFile)) {
119-
IOUtils.copy(inputStream, outputStream);
120-
}
121-
connection.disconnect();
122-
}
103+
File gzFile = downloadFile(PIGGYMETRICS_TAR_GZ_URL);
123104

124105
deployment = app.deployments().define(deploymentName1)
125106
.withSourceCodeTarGzFile(gzFile)
@@ -144,12 +125,8 @@ public void canCRUDDeployment() throws Exception {
144125
}
145126

146127
@Test
147-
@DoNotRecord
128+
@DoNotRecord(skipInPlayback = true)
148129
public void canCreateCustomDomainWithSsl() throws Exception {
149-
if (skipInPlayback()) {
150-
return;
151-
}
152-
153130
String domainName = generateRandomResourceName("jsdkdemo-", 20) + ".com";
154131
String certOrderName = generateRandomResourceName("cert", 15);
155132
String vaultName = generateRandomResourceName("vault", 15);
@@ -254,10 +231,93 @@ public void canCreateCustomDomainWithSsl() throws Exception {
254231

255232
app.update()
256233
.withHttpsOnly()
234+
.withoutCustomDomain(String.format("www.%s", domainName))
257235
.apply();
258236
Assertions.assertTrue(checkRedirect(String.format("http://ssl.%s", domainName)));
259237
}
260238

239+
@Test
240+
@DoNotRecord(skipInPlayback = true)
241+
public void canCRUDEnterpriseTierDeployment() throws Exception {
242+
allowAllSSL();
243+
File tarGzFile = downloadFile(PETCLINIC_TAR_GZ_URL);
244+
File jarFile = downloadFile(PETCLINIC_GATEWAY_JAR_URL);
245+
246+
String serviceName = generateRandomResourceName("springsvc", 15);
247+
Region region = Region.US_EAST;
248+
249+
List<String> configFilePatterns = Arrays.asList("api-gateway", "customers-service");
250+
SpringService service = appPlatformManager.springServices().define(serviceName)
251+
.withRegion(region)
252+
.withNewResourceGroup(rgName)
253+
.withEnterpriseTierSku()
254+
.withDefaultGitRepository(PETCLINIC_CONFIG_URL, "master", configFilePatterns)
255+
.create();
256+
257+
String deploymentName = generateRandomResourceName("deploy", 15);
258+
259+
List<String> apiGatewayConfigFilePatterns = Arrays.asList("api-gateway");
260+
String appName = "api-gateway";
261+
SpringApp app = service.apps().define(appName)
262+
.defineActiveDeployment(deploymentName)
263+
.withJarFile(jarFile)
264+
.withInstance(2)
265+
.withCpu("500m")
266+
.withMemory("512Mi")
267+
.attach()
268+
.withDefaultPublicEndpoint()
269+
.withConfigurationServiceBinding()
270+
.create();
271+
272+
SpringAppDeployment deployment = app.deployments().getByName(deploymentName);
273+
Assertions.assertTrue(CoreUtils.isNullOrEmpty(deployment.configFilePatterns()));
274+
275+
deployment.update()
276+
.withConfigFilePatterns(apiGatewayConfigFilePatterns)
277+
.apply();
278+
279+
deployment.refresh();
280+
Assertions.assertFalse(CoreUtils.isNullOrEmpty(deployment.configFilePatterns()));
281+
282+
Assertions.assertNotNull(app.url());
283+
Assertions.assertNotNull(app.activeDeploymentName());
284+
Assertions.assertEquals(1, app.deployments().list().stream().count());
285+
286+
String appName2 = "customers-service";
287+
String module = "spring-petclinic-customers-service";
288+
List<String> customerServiceConfigFilePatterns = Arrays.asList("customers-service");
289+
SpringApp app2 = service.apps().define(appName2)
290+
.defineActiveDeployment(deploymentName)
291+
.withSourceCodeTarGzFile(tarGzFile, customerServiceConfigFilePatterns)
292+
.withTargetModule(module)
293+
.attach()
294+
.withConfigurationServiceBinding()
295+
.create();
296+
297+
// no public endpoint
298+
Assertions.assertNull(app2.url());
299+
300+
SpringAppDeployment customersDeployment = app2.deployments().getByName(deploymentName);
301+
Assertions.assertEquals(customerServiceConfigFilePatterns, customersDeployment.configFilePatterns());
302+
}
303+
304+
private File downloadFile(String remoteFileUrl) throws Exception {
305+
String[] split = remoteFileUrl.split("/");
306+
String filename = split[split.length - 1];
307+
File downloaded = new File(filename);
308+
if (!downloaded.exists()) {
309+
HttpURLConnection connection = (HttpURLConnection) new URL(remoteFileUrl).openConnection();
310+
connection.connect();
311+
try (InputStream inputStream = connection.getInputStream();
312+
OutputStream outputStream = new FileOutputStream(downloaded)) {
313+
IOUtils.copy(inputStream, outputStream);
314+
} finally {
315+
connection.disconnect();
316+
}
317+
}
318+
return downloaded;
319+
}
320+
261321
private void extraTarGzSource(File folder, URL url) throws IOException {
262322
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
263323
connection.connect();

0 commit comments

Comments
 (0)