Feature Flags service Demo Application is a simple Spring Boot application that consumes the Feature Flags service on SAP Cloud Platform, Cloud Foundry environment. It implements a feature toggle (evaluation call to the Feature Flags service) and exposes this feature toggle through a Web user interface. There is also one REST end-point that reads the value of VCAP_SERVICES
environment variable.
- have set up Maven 3.0.x
- have an SAP Cloud Platform trial account on Cloud Foundry environment
- have a trial space on a Cloud Foundry instance
- have set up a curl plug-in for cmd
- have installed cf CLI
Follow these steps to run the Feature Flags Service Demo application on SAP Cloud Platform, Cloud Foundry environment.
Note: This guide uses the Cloud Foundry trial account on Europe (Frankfurt) region (https://account.hanatrial.ondemand.com/cockpit#/home/overview). If you want to use a different region, you have to modify the domain in the requests. For more information about regions and hosts on SAP Cloud Platform, Cloud Foundry environment, see Regions and Hosts.
- Build the application.
- Edit the manifest.yml.
- Deploy the application.
- Create a service instance of the Feature Flag service.
- Call feature-flags-demo application /vcap_services end-point.
- Bind feature-flags-demo to feature-flags-instance.
- Restage feature-flags-demo application.
- Ensure that feature-flags-instance is properly bound to feature-flags-demo.
- Perform an evaluation of missing feature flag.
- Create a new feature flag.
- Perform an evaluation of the newly created feature flag.
- Enable the feature flag.
- Verify that the feature flag was properly enabled.
$ git clone [email protected]:SAP/cloud-cf-feature-flags-sample.git
$ cd cloud-cf-feature-flags-sample
$ mvn clean install
Note: Alternatively, you can use the Eclipse IDE, use the
clean install
goal from Run As > Maven Build... menu.
Due to CloudFoundry's limitiation in regards to application naming it's quite possible for someone to have already deployed the Feature Flags demo application with the feature-flags-demo name as it is currently set in the manifest.yml file. CloudFoundry will not allow another application with the same name to be deployed, so you MUST edit the manifest file and change the application name before deploying. For example:
---
applications:
- name: feature-flags-demo123
path: target/feature-flags-demo.jar
$ cf api https://api.cf.eu10.hana.ondemand.com
$ cf login
$ cf push
$ cf marketplace
-----
Getting services from marketplace in org <ORG_ID> / space dev as <USER_ID>...
OK
service plans description
...
feature-flags lite Feature Flags service for controlling feature rollout
...
$ cf create-service feature-flags lite feature-flags-instance
-----
Creating service instance feature-flags-instance in org <ORG_ID> / space dev as <USER_ID>...
OK
Note: Alternatively, you can also use the SAP Cloud Platform Cockpit. See Create a Service Instance.
Note: Expect to receive an empty JSON.
The /vcap_services end-point simply returns the content of VCAP_SERVICES environment variable. As for now there is no service instances bound to feature-flags-demo
, so you will receive an empty JSON.
In the command you use the following URL: <application_URL>/vcap_services. You can find the <application_URL> in the SAP Cloud Platform Cockpit, in the feature-flag-demo > Overview > Application Routes.
$ curl https://feature-flags-demo.cfapps.eu10.hana.ondemand.com/vcap_services
$ cf bind-service feature-flags-demo feature-flags-instance
-----
Binding service feature-flags-instance to app feature-flags-demo in org <ORG_ID> / space dev as <USER_ID>...
OK
TIP: Use 'cf restage feature-flags-demo' to ensure your env variable changes take effect
Note: Alternatively, you can also use the SAP Cloud Platform Cockpit. See Bind Your Application to the Feature Flags Service Instance.
Restage feature-flags-demo
application so the changes in the application environment take effect.
$ cf restage feature-flags-demo
Note: Expect to receive the injected environment variables by the Feature Flags service.
$ curl https://feature-flags-demo.cfapps.eu10.hana.ondemand.com/vcap_services
Sample JSON response:
{
"feature-flags": [
{
"credentials": {
"password": "aa_GgZf1GIDZbuXV9s0RknzRE+qs0e=",
"uri": "https://feature-flags.cfapps.eu10.hana.ondemand.com",
"username": "sbss_x324osjl//pmabsuskr6nshmb2arw6dld4hfb3cj4m2bonkqmm3ts6c68mdpzxz2fma="
},
"syslog_drain_url": null,
"volume_mounts": [ ],
"label": "feature-flags",
"provider": null,
"plan": "lite",
"name": "feature-flags-instance",
"tags": [
"feature-flags"
]
}
]
}
Note: Expect the feature flag to be missing.
- Navigate to feature-flags-demo overview in the SAP Cloud Platform Cockpit (for example, https://feature-flags-demo.cfapps.eu10.hana.ondemand.com). An Evaluation Form opens.
- Evaluate a feature flag with random name (for example, type in 'my-flag'). The result should state that the feature flag with the given name is missing.
- Navigate to Feature Flags service instance dashboard in the SAP Cloud Platform Cockpit (for example, https://feature-flags-dashboard.cfapps.eu10.hana.ondemand.com/manageinstances/<instance-id>). The instance ID is a unique ID of the service instance.
Note: The easiest way to access the Feature Flags dashboard is through the cockpit. Go to <your_subaccount> > <your_space> > Service Instances > Actions (from your service instance line) > Open Dashboard icon.
- Choose New Flag.
- Fill in the required fields (for example, 'my-flag' for Name, 'Super cool feature' for Description and 'OFF' for State).
- Choose Add.
Note: Expect the feature flag to be disabled.
- Navigate to feature-flags-demo application overview in the SAP Cloud Platform Cockpit. Open the link from the Application Routes section (for example, https://feature-flags-demo.cfapps.eu10.hana.ondemand.com). An Evaluation Form opens.
- Enter the feature flag name in the Feature Flag Name field and choose Evaluate.
- Evaluate the newly created feature flag. The result should state that the feature flag with the given name is disabled.
- Navigate to Feature Flags service instance dashboard in the SAP Cloud Platform Cockpit (for example, https://feature-flags-dashboard.cfapps.eu10.hana.ondemand.com/manageinstances/<instance-id>). The instance ID is a unique ID of the service instance.
Note: The easiest way to access the Feature Flags dashboard is through the cockpit. Go to <your_subaccount> > <your_space> > Service Instances > Actions (from your service instance line) > Open Dashboard icon.
- Enable the feature flag using the switch in the State column.
Note: Expect the feature flag to be enabled.
- Navigate to feature-flags-demo application overview in the SAP Cloud Platform Cockpit. Open the link from the Application Routes section (for example, https://feature-flags-demo.cfapps.eu10.hana.ondemand.com). An Evaluation Form opens.
- Enter the feature flag name in the Feature Flag Name field and choose Evaluate.
- Evaluate the feature flag. The result should state that the feature flag with the given name is enabled.