Environment Toggles Design
Background ¶
MCT has various of environment deployments, such as commercial and PSF (Public Sector Foundations). Maybe there will have more environments future.
So some functions will need to be controlled to run or not for some MCT services by environment toggles.
Environment Toggles and MCT Services Mapping ¶
| MCT Services | Configuration File Name | Field Name | Values |
|---|---|---|---|
| central api | api.properties | platform | il5 / psf / commercial |
| job engine | webexmct.properties | platform | il5 / psf / commercial |
| status api | gpi.properties | platform | il5 / psf / commercial |
Business Cover Examples ¶
How we can use the environment toggles for business logical, following are some examples in code.
XML Import Condition ¶
The RabbitMQ will just work in commercial for central api and status api. Before we imported xml in application xml directly, but we need to control if loading xml by using platform field now.
For java code
public class RabbitMQCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return PlatformEnum.COMMERCIAL.isSystemMatch();
}
}
@Configuration
@Conditional(RabbitMQCondition.class)
@ImportResource("classpath*:spring-rabbit.xml")
public class RabbitMQLoadConfiguration {
}
// class RabbitMQSender will only be initialized when RabbitMQCondition.matches() returns true.
@Component
@Conditional(RabbitMQCondition.class)
public class RabbitMQSender {
//
}
For application xml configuration
<bean class="com.webex.mct.platform.configuration.RabbitMQLoadConfiguration"/>
Platform Annotation for Method ¶
Some tasks can be controlled to run or not by annotation for job engine.
For java code
@org.springframework.stereotype.Service("UpdateTestSiteTask")
public class UpdateTestSiteTask extends BaseTask {
@Override
@Platform(Platform.PlatformEnum.COMMERCIAL)
public void execute() throws PlatformException {
//
}
}
Platform Annotation for Class ¶
This field can control if this component can be scanned or not in central-api. The code business logical is in mct-shared by PlatformFilter.
For java code
@Component
@Path("/vendor")
@Api(value = "/vendor", description = "get vendor item")
@Platform(Platform.PlatformEnum.COMMERCIAL)
public class VendorDetailWebService extends BaseWebService {
//
}