Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static void uploadFileToWebApp(PublishingProfile profile, String fileName

protected Response<String> curl(String urlString) throws IOException {
try {
Mono<SimpleResponse<Flux<ByteBuffer>>> response =
Mono<Response<Flux<ByteBuffer>>> response =
HTTP_CLIENT.getString(getHost(urlString), getPathAndQuery(urlString))
.retryWhen(Retry
.fixedDelay(3, Duration.ofSeconds(30))
Expand Down Expand Up @@ -235,7 +235,7 @@ private String getPathAndQuery(String urlString) throws MalformedURLException {
return path;
}

private static Mono<SimpleResponse<String>> stringResponse(Mono<SimpleResponse<Flux<ByteBuffer>>> responseMono) {
private static Mono<Response<String>> stringResponse(Mono<Response<Flux<ByteBuffer>>> responseMono) {
return responseMono
.flatMap(
response ->
Expand Down Expand Up @@ -263,12 +263,12 @@ private static Mono<SimpleResponse<String>> stringResponse(Mono<SimpleResponse<F
private interface WebAppTestClient {
@Get("{path}")
@ExpectedResponses({200, 400, 404})
Mono<SimpleResponse<Flux<ByteBuffer>>> getString(
Mono<Response<Flux<ByteBuffer>>> getString(
@HostParam("$host") String host, @PathParam(value = "path", encoded = true) String path);

@Post("{path}")
@ExpectedResponses({200, 400, 404})
Mono<SimpleResponse<Flux<ByteBuffer>>> postString(
Mono<Response<Flux<ByteBuffer>>> postString(
@HostParam("$host") String host,
@PathParam(value = "path", encoded = true) String path,
@BodyParam("text/plain") String body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,23 +251,6 @@ public String randomResourceName(String prefix, int maxLen) {
return identifierFunction.apply("").getRandomName(prefix, maxLen);
}

/**
* Generates the specified number of random resource names with the same prefix.
*
* @param prefix the prefix to be used if possible
* @param maxLen the maximum length for the random generated name
* @param count the number of names to generate
* @return random names
*/
public String[] randomResourceNames(String prefix, int maxLen, int count) {
String[] names = new String[count];
IdentifierProvider resourceNamer = identifierFunction.apply("");
for (int i = 0; i < count; i++) {
names[i] = resourceNamer.getRandomName(prefix, maxLen);
}
return names;
}

/**
* Gets a random UUID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ public class ManageSpringCloud {
* @throws IllegalStateException unexcepted state
*/
public static boolean runSample(AzureResourceManager azureResourceManager, String clientId) throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
final String rgName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("rg", 24);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide these to Utils.

final String serviceName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("service", 24);
final String rgName = Utils.randomResourceName(azureResourceManager, "rg", 24);
final String serviceName = Utils.randomResourceName(azureResourceManager, "service", 24);
final Region region = Region.US_EAST;
final String domainName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("jsdkdemo-", 20) + ".com";
final String certOrderName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("cert", 15);
final String vaultName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("vault", 15);
final String certName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("cert", 15);
final String domainName = Utils.randomResourceName(azureResourceManager, "jsdkdemo-", 20) + ".com";
final String certOrderName = Utils.randomResourceName(azureResourceManager, "cert", 15);
final String vaultName = Utils.randomResourceName(azureResourceManager, "vault", 15);
final String certName = Utils.randomResourceName(azureResourceManager, "cert", 15);

try {
azureResourceManager.resourceGroups().define(rgName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public final class ManageFunctionAppBasic {
*/
public static boolean runSample(AzureResourceManager azureResourceManager) {
// New resources
final String app1Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp1-", 20);
final String app2Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp2-", 20);
final String app3Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp3-", 20);
final String rg1Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("rg1NEMV_", 24);
final String rg2Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("rg2NEMV_", 24);
final String app1Name = Utils.randomResourceName(azureResourceManager, "webapp1-", 20);
final String app2Name = Utils.randomResourceName(azureResourceManager, "webapp2-", 20);
final String app3Name = Utils.randomResourceName(azureResourceManager, "webapp3-", 20);
final String rg1Name = Utils.randomResourceName(azureResourceManager, "rg1NEMV_", 24);
final String rg2Name = Utils.randomResourceName(azureResourceManager, "rg2NEMV_", 24);

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public final class ManageFunctionAppLogs {
public static boolean runSample(AzureResourceManager azureResourceManager) throws IOException {
// New resources
final String suffix = ".azurewebsites.net";
final String appName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp1-", 20);
final String appName = Utils.randomResourceName(azureResourceManager, "webapp1-", 20);
final String appUrl = appName + suffix;
final String rgName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("rg1NEMV_", 24);
final String rgName = Utils.randomResourceName(azureResourceManager, "rg1NEMV_", 24);

try {

Expand Down Expand Up @@ -71,9 +71,9 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

System.out.println("Deploying a function app to " + appName + " through FTP...");

Utils.uploadFileViaFtp(app.getPublishingProfile(), "host.json", ManageFunctionAppLogs.class.getResourceAsStream("/square-function-app/host.json"));
Utils.uploadFileViaFtp(app.getPublishingProfile(), "square/function.json", ManageFunctionAppLogs.class.getResourceAsStream("/square-function-app/square/function.json"));
Utils.uploadFileViaFtp(app.getPublishingProfile(), "square/index.js", ManageFunctionAppLogs.class.getResourceAsStream("/square-function-app/square/index.js"));
Utils.uploadFileForFunctionViaFtp(app.getPublishingProfile(), "host.json", ManageFunctionAppLogs.class.getResourceAsStream("/square-function-app/host.json"));
Utils.uploadFileForFunctionViaFtp(app.getPublishingProfile(), "square/function.json", ManageFunctionAppLogs.class.getResourceAsStream("/square-function-app/square/function.json"));
Utils.uploadFileForFunctionViaFtp(app.getPublishingProfile(), "square/index.js", ManageFunctionAppLogs.class.getResourceAsStream("/square-function-app/square/index.js"));

// sync triggers
app.syncTriggers();
Expand All @@ -83,7 +83,7 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

// warm up
System.out.println("Warming up " + appUrl + "/api/square...");
Utils.post("http://" + appUrl + "/api/square", "625");
Utils.sendPostRequest("http://" + appUrl + "/api/square", "625");
ResourceManagerUtils.sleep(Duration.ofSeconds(5));

//============================================================
Expand All @@ -95,11 +95,11 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw
StopWatch stopWatch = new StopWatch();
stopWatch.start();
new Thread(() -> {
Utils.post("http://" + appUrl + "/api/square", "625");
Utils.sendPostRequest("http://" + appUrl + "/api/square", "625");
ResourceManagerUtils.sleep(Duration.ofSeconds(10));
Utils.post("http://" + appUrl + "/api/square", "725");
Utils.sendPostRequest("http://" + appUrl + "/api/square", "725");
ResourceManagerUtils.sleep(Duration.ofSeconds(10));
Utils.post("http://" + appUrl + "/api/square", "825");
Utils.sendPostRequest("http://" + appUrl + "/api/square", "825");
}).start();
while (line != null && stopWatch.getTime() < 90000) {
System.out.println(line);
Expand All @@ -113,11 +113,11 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw
new Thread(() -> {
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
System.out.println("Starting hitting");
Utils.post("http://" + appUrl + "/api/square", "625");
Utils.sendPostRequest("http://" + appUrl + "/api/square", "625");
ResourceManagerUtils.sleep(Duration.ofSeconds(10));
Utils.post("http://" + appUrl + "/api/square", "725");
Utils.sendPostRequest("http://" + appUrl + "/api/square", "725");
ResourceManagerUtils.sleep(Duration.ofSeconds(10));
Utils.post("http://" + appUrl + "/api/square", "825");
Utils.sendPostRequest("http://" + appUrl + "/api/square", "825");
}).start();

final AtomicInteger count = new AtomicInteger(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ public final class ManageFunctionAppSourceControl {
public static boolean runSample(AzureResourceManager azureResourceManager) throws GitAPIException {
// New resources
final String suffix = ".azurewebsites.net";
final String app1Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp1-", 20);
final String app2Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp2-", 20);
final String app3Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp3-", 20);
final String app4Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp4-", 20);
final String app5Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp5-", 20);
final String app6Name = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("webapp6-", 20);
final String app1Name = Utils.randomResourceName(azureResourceManager, "webapp1-", 20);
final String app2Name = Utils.randomResourceName(azureResourceManager, "webapp2-", 20);
final String app3Name = Utils.randomResourceName(azureResourceManager, "webapp3-", 20);
final String app4Name = Utils.randomResourceName(azureResourceManager, "webapp4-", 20);
final String app5Name = Utils.randomResourceName(azureResourceManager, "webapp5-", 20);
final String app6Name = Utils.randomResourceName(azureResourceManager, "webapp6-", 20);
final String app1Url = app1Name + suffix;
final String app2Url = app2Name + suffix;
final String app3Url = app3Name + suffix;
final String app4Url = app4Name + suffix;
final String app5Url = app5Name + suffix;
final String app6Url = app6Name + suffix;
final String rgName = azureResourceManager.resourceGroups().manager().internalContext().randomResourceName("rg1NEMV_", 24);
final String rgName = Utils.randomResourceName(azureResourceManager, "rg1NEMV_", 24);

try {

Expand All @@ -80,9 +80,9 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

System.out.println("Deploying a function app to " + app1Name + " through FTP...");

Utils.uploadFileViaFtp(app1.getPublishingProfile(), "host.json", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/host.json"));
Utils.uploadFileViaFtp(app1.getPublishingProfile(), "square/function.json", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/square/function.json"));
Utils.uploadFileViaFtp(app1.getPublishingProfile(), "square/index.js", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/square/index.js"));
Utils.uploadFileForFunctionViaFtp(app1.getPublishingProfile(), "host.json", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/host.json"));
Utils.uploadFileForFunctionViaFtp(app1.getPublishingProfile(), "square/function.json", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/square/function.json"));
Utils.uploadFileForFunctionViaFtp(app1.getPublishingProfile(), "square/index.js", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/square/index.js"));

// sync triggers
app1.syncTriggers();
Expand All @@ -92,10 +92,10 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

// warm up
System.out.println("Warming up " + app1Url + "/api/square...");
Utils.post("http://" + app1Url + "/api/square", "625");
Utils.sendPostRequest("http://" + app1Url + "/api/square", "625");
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
System.out.println("CURLing " + app1Url + "/api/square...");
System.out.println("Square of 625 is " + Utils.post("http://" + app1Url + "/api/square", "625"));
System.out.println("Square of 625 is " + Utils.sendPostRequest("http://" + app1Url + "/api/square", "625"));

//============================================================
// Create a second function app with local git source control
Expand Down Expand Up @@ -136,10 +136,10 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

// warm up
System.out.println("Warming up " + app2Url + "/api/square...");
Utils.post("http://" + app2Url + "/api/square", "725");
Utils.sendPostRequest("http://" + app2Url + "/api/square", "725");
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
System.out.println("CURLing " + app2Url + "/api/square...");
System.out.println("Square of 725 is " + Utils.post("http://" + app2Url + "/api/square", "725"));
System.out.println("Square of 725 is " + Utils.sendPostRequest("http://" + app2Url + "/api/square", "725"));

//============================================================
// Create a 3rd function app with a public GitHub repo in Azure-Samples
Expand All @@ -160,10 +160,10 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

// warm up
System.out.println("Warming up " + app3Url + "/api/square...");
Utils.post("http://" + app3Url + "/api/square", "825");
Utils.sendPostRequest("http://" + app3Url + "/api/square", "825");
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
System.out.println("CURLing " + app3Url + "/api/square...");
System.out.println("Square of 825 is " + Utils.post("http://" + app3Url + "/api/square", "825"));
System.out.println("Square of 825 is " + Utils.sendPostRequest("http://" + app3Url + "/api/square", "825"));

//============================================================
// Create a 4th function app with a personal GitHub repo and turn on continuous integration
Expand All @@ -187,10 +187,10 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

// warm up
System.out.println("Warming up " + app4Url + "...");
Utils.curl("http://" + app4Url);
Utils.sendGetRequest("http://" + app4Url);
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
System.out.println("CURLing " + app4Url + "...");
System.out.println(Utils.curl("http://" + app4Url));
System.out.println(Utils.sendGetRequest("http://" + app4Url));

//============================================================
// Create a 5th function app with web deploy
Expand All @@ -213,10 +213,10 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

// warm up
System.out.println("Warming up " + app5Url + "/api/square...");
Utils.post("http://" + app5Url + "/api/square", "925");
Utils.sendPostRequest("http://" + app5Url + "/api/square", "925");
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
System.out.println("CURLing " + app5Url + "/api/square...");
System.out.println("Square of 925 is " + Utils.post("http://" + app5Url + "/api/square", "925"));
System.out.println("Square of 925 is " + Utils.sendPostRequest("http://" + app5Url + "/api/square", "925"));

//============================================================
// Create a 6th function app with zip deploy
Expand All @@ -239,10 +239,10 @@ public static boolean runSample(AzureResourceManager azureResourceManager) throw

// warm up
System.out.println("Warming up " + app6Url + "/api/square...");
Utils.post("http://" + app6Url + "/api/square", "926");
Utils.sendPostRequest("http://" + app6Url + "/api/square", "926");
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
System.out.println("CURLing " + app6Url + "/api/square...");
System.out.println("Square of 926 is " + Utils.post("http://" + app6Url + "/api/square", "926"));
System.out.println("Square of 926 is " + Utils.sendPostRequest("http://" + app6Url + "/api/square", "926"));

return true;
} finally {
Expand Down
Loading