Skip to content

Commit

Permalink
mgmt appplatform configuration service binding (Azure#28418)
Browse files Browse the repository at this point in the history
* support configuration service app binding

* session records

* changelog

* javadoc
  • Loading branch information
XiaofeiCao authored Apr 21, 2022
1 parent 0448dfa commit 5308ebb
Show file tree
Hide file tree
Showing 8 changed files with 1,069 additions and 1,059 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Supported Enterprise Tier `Configuration Service`.
- Supported Enterprise Tier `Build Service`.
- Supported Enterprise Tier binding `Spring App` to `Configuration Service`.

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

package com.azure.resourcemanager.appplatform.implementation;

/** (internal use) Implementation-shared constants. */
/** (Internal Use Only) Implementation-shared constants. */
class Constants {
public static final String DEFAULT_TANZU_COMPONENT_NAME = "default";
public static final String APPLICATION_CONFIGURATION_SERVICE_KEY = "applicationConfigurationService";
public static final String BINDING_RESOURCE_ID = "resourceId";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.azure.resourcemanager.appplatform.models.SpringAppDeployments;
import com.azure.resourcemanager.appplatform.models.SpringAppDomains;
import com.azure.resourcemanager.appplatform.models.SpringAppServiceBindings;
import com.azure.resourcemanager.appplatform.models.SpringConfigurationService;
import com.azure.resourcemanager.appplatform.models.SpringService;
import com.azure.resourcemanager.appplatform.models.TemporaryDisk;
import com.azure.resourcemanager.appplatform.models.UserSourceType;
Expand All @@ -27,6 +28,9 @@
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

public class SpringAppImpl
Expand Down Expand Up @@ -145,6 +149,23 @@ private void ensureProperty() {
}
}

@Override
public boolean hasConfigurationServiceBinding() {
Map<String, Map<String, Object>> addonConfigs = innerModel().properties().addonConfigs();
if (addonConfigs == null) {
return false;
}
SpringConfigurationService configurationService = parent().getDefaultConfigurationService();
if (configurationService == null) {
return false;
}
return addonConfigs.get(Constants.APPLICATION_CONFIGURATION_SERVICE_KEY) != null
&& Objects.equals(
addonConfigs.get(Constants.APPLICATION_CONFIGURATION_SERVICE_KEY).get(Constants.BINDING_RESOURCE_ID),
configurationService.id()
);
}

@Override
public SpringAppImpl withDefaultPublicEndpoint() {
ensureProperty();
Expand Down Expand Up @@ -307,4 +328,34 @@ SpringAppImpl addActiveDeployment(SpringAppDeploymentImpl deployment) {
springAppDeploymentToCreate = deployment;
return this;
}

@Override
public SpringAppImpl withConfigurationServiceBinding() {
ensureProperty();
Map<String, Map<String, Object>> addonConfigs = innerModel().properties().addonConfigs();
if (addonConfigs == null) {
addonConfigs = new HashMap<>();
innerModel().properties().withAddonConfigs(addonConfigs);
}
Map<String, Object> configurationServiceConfigs = addonConfigs.computeIfAbsent(Constants.APPLICATION_CONFIGURATION_SERVICE_KEY, k -> new HashMap<>());
configurationServiceConfigs.put(Constants.BINDING_RESOURCE_ID, parent().getDefaultConfigurationService().id());
return this;
}

@Override
public SpringAppImpl withoutConfigurationServiceBinding() {
if (innerModel().properties() == null) {
return this;
}
Map<String, Map<String, Object>> addonConfigs = innerModel().properties().addonConfigs();
if (addonConfigs == null) {
return this;
}
Map<String, Object> configurationServiceConfigs = addonConfigs.get(Constants.APPLICATION_CONFIGURATION_SERVICE_KEY);
if (configurationServiceConfigs == null) {
return this;
}
configurationServiceConfigs.put(Constants.BINDING_RESOURCE_ID, "");
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.resourcemanager.appplatform.fluent.models.ConfigurationServiceResourceInner;
import com.azure.resourcemanager.appplatform.models.ConfigurationServiceGitProperty;
import com.azure.resourcemanager.appplatform.models.ConfigurationServiceGitRepository;
import com.azure.resourcemanager.appplatform.models.SpringApp;
import com.azure.resourcemanager.appplatform.models.SpringConfigurationService;
import com.azure.resourcemanager.appplatform.models.SpringService;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.ExternalChildResourceImpl;
Expand All @@ -15,6 +16,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class SpringConfigurationServiceImpl
extends ExternalChildResourceImpl<SpringConfigurationService, ConfigurationServiceResourceInner, SpringServiceImpl, SpringService>
Expand Down Expand Up @@ -62,6 +64,11 @@ private Optional<ConfigurationServiceGitRepository> findDefaultRepository() {
return findRepository(Constants.DEFAULT_TANZU_COMPONENT_NAME);
}

@Override
public List<SpringApp> getAppBindings() {
return parent().apps().list().stream().filter(SpringApp::hasConfigurationServiceBinding).collect(Collectors.toList());
}

private Optional<ConfigurationServiceGitRepository> findRepository(String name) {
if (name == null || innerModel().properties() == null || innerModel().properties().settings() == null) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public interface SpringApp
/** @return the blob url to upload deployment */
ResourceUploadDefinition getResourceUploadUrl();

/**
* (Enterprise Tier Only)
* @return whether this app has binding to the default Configuration Service
*/
boolean hasConfigurationServiceBinding();

/** Container interface for all the definitions that need to be implemented. */
interface Definition
extends DefinitionStages.Blank,
Expand Down Expand Up @@ -164,6 +170,27 @@ interface WithServiceBinding {
WithCreate withoutServiceBinding(String name);
}

/**
* (Enterprise Tier Only)
* The stage of spring app definition allowing to bind it to default configuration service.
*/
interface WithConfigurationServiceBinding {
/**
* Specifies a binding to the default configuration service.
* To use the centralized configurations, you must bind the app to Application Configuration Service for Tanzu.
* When you change the bind/unbind status, you must restart or redeploy the app to for the binding to take effect.
* @return the next stage of spring app definition
*/
WithCreate withConfigurationServiceBinding();

/**
* Removes a binding to the default configuration service.
* When you change the bind/unbind status, you must restart or redeploy the app to for the binding to take effect.
* @return the next stage of spring app definition
*/
WithCreate withoutConfigurationServiceBinding();
}

/**
* The stage of the definition which contains all the minimum required inputs for the resource to be created,
* but also allows for any other optional settings to be specified.
Expand All @@ -173,7 +200,8 @@ interface WithCreate
DefinitionStages.WithEndpoint,
DefinitionStages.WithDisk,
DefinitionStages.WithDeployment,
DefinitionStages.WithServiceBinding { }
DefinitionStages.WithServiceBinding,
DefinitionStages.WithConfigurationServiceBinding { }
}

/** The template for an update operation, containing all the settings that can be modified. */
Expand All @@ -182,7 +210,8 @@ interface Update
UpdateStages.WithEndpoint,
UpdateStages.WithDisk,
UpdateStages.WithDeployment,
UpdateStages.WithServiceBinding { }
UpdateStages.WithServiceBinding,
UpdateStages.WithConfigurationServiceBinding { }

/** Grouping of spring app update stages. */
interface UpdateStages {
Expand Down Expand Up @@ -284,5 +313,26 @@ interface WithServiceBinding {
*/
Update withoutServiceBinding(String name);
}

/**
* (Enterprise Tier Only)
* The stage of a spring app update allowing to bind it to the default configuration service.
*/
interface WithConfigurationServiceBinding {
/**
* Specifies a binding to the default configuration service.
* To use the centralized configurations, you must bind the app to Application Configuration Service for Tanzu.
* When you change the bind/unbind status, you must restart or redeploy the app to for the binding to take effect.
* @return the next stage of spring app update
*/
Update withConfigurationServiceBinding();

/**
* Removes a binding to the default configuration service.
* When you change the bind/unbind status, you must restart or redeploy the app to for the binding to take effect.
* @return the next stage of spring app update
*/
Update withoutConfigurationServiceBinding();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ public interface SpringConfigurationService
* @return git repository config
*/
ConfigurationServiceGitRepository getGitRepository(String name);

/** @return apps that have bindings to this Configuration Service */
List<SpringApp> getAppBindings();
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,24 @@ public void canCRUDApp() {
.withDefaultActiveDeployment()
.withHttpsOnly()
.withDefaultPublicEndpoint()
.withConfigurationServiceBinding()
.create();

Assertions.assertNotNull(app.url());
Assertions.assertTrue(app.isHttpsOnly());
Assertions.assertTrue(app.isPublic());
Assertions.assertTrue(app.hasConfigurationServiceBinding());
Assertions.assertTrue(springService.getDefaultConfigurationService().getAppBindings().stream().anyMatch(SpringApp::hasConfigurationServiceBinding));

app.update()
.withoutHttpsOnly()
.withoutDefaultPublicEndpoint()
.withoutConfigurationServiceBinding()
.apply();

Assertions.assertFalse(app.isHttpsOnly());
Assertions.assertFalse(app.isPublic());
Assertions.assertFalse(app.hasConfigurationServiceBinding());
Assertions.assertFalse(springService.getDefaultConfigurationService().getAppBindings().stream().anyMatch(SpringApp::hasConfigurationServiceBinding));
}
}
Loading

0 comments on commit 5308ebb

Please sign in to comment.