com.sap.cds.services.mt.impl.MtDeploymentServiceConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cds-feature-mt Show documentation
Show all versions of cds-feature-mt Show documentation
Multi tenancy feature for CDS Services Java
/**************************************************************************
* (C) 2019-2021 SAP SE or an SAP affiliate company. All rights reserved. *
**************************************************************************/
package com.sap.cds.services.mt.impl;
import java.util.Optional;
import com.sap.cds.feature.mt.MtUtils;
import com.sap.cds.feature.mt.SaasClient;
import com.sap.cds.services.environment.ServiceBinding;
import com.sap.cds.services.mt.ExtensibilityService;
import com.sap.cds.services.mt.MtSubscriptionService;
import com.sap.cds.services.runtime.CdsRuntimeConfiguration;
import com.sap.cds.services.runtime.CdsRuntimeConfigurer;
import com.sap.cds.services.utils.model.DynamicModelUtils;
import com.sap.cloud.mt.subscription.InstanceLifecycleManager;
@SuppressWarnings("deprecation")
public class MtDeploymentServiceConfiguration implements CdsRuntimeConfiguration {
@Override
public void services(CdsRuntimeConfigurer configurer) {
boolean compatibility = configurer.getCdsRuntime().getEnvironment().getCdsProperties().getMultiTenancy().getCompatibility().isEnabled();
if (new MtUtils(configurer.getCdsRuntime()).requiresSubscription() && compatibility) {
configurer.service(new MtSubscriptionServiceImpl(MtSubscriptionService.DEFAULT_NAME));
}
// isDynamicModelEnabled() doesn't fully guarantee extensibility usage (e.g. might only be feature toggles usage)
if (new DynamicModelUtils(configurer.getCdsRuntime()).isDynamicModelEnabled()) {
configurer.service(new ExtensibilityServiceImpl(ExtensibilityService.DEFAULT_NAME));
}
}
@Override
public void eventHandlers(CdsRuntimeConfigurer configurer) {
MtUtils mtUtils = new MtUtils(configurer.getCdsRuntime());
InstanceLifecycleManager ilm = mtUtils.createDefaultInstanceLifecycleManager();
Optional saasBinding = SaasClient.findBinding(configurer.getCdsRuntime());
if (saasBinding.isPresent()) {
configurer.eventHandler(new MtTenantProviderSaasHandler(saasBinding.get()));
}
if (ilm != null) {
// adding this provider as well. SaaS handler is taken with priority based on the handler order
configurer.eventHandler(new MtTenantProviderHandler(ilm));
}
if (mtUtils.requiresSubscription()) {
boolean compatibility = configurer.getCdsRuntime().getEnvironment().getCdsProperties().getMultiTenancy().getCompatibility().isEnabled();
if (compatibility) {
configurer.eventHandler(new MtSubscriptionServiceCompatibilityHandler(ilm, configurer.getCdsRuntime()));
} else {
configurer.eventHandler(new MtDeploymentServiceHandler(ilm, configurer.getCdsRuntime()));
}
// inform outbox about mt enablement, as persistent outbox is not usable for provider tenant on tenant-aware databases
configurer.getCdsRuntime().getEnvironment().getCdsProperties().getOutbox().getPersistent().getProviderTenant().setEnabled(false);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy