Search in sources :

Example 11 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig in project knox by apache.

the class HaProviderDeploymentContributor method contributeProvider.

@Override
public void contributeProvider(DeploymentContext context, Provider provider) {
    Topology topology = context.getTopology();
    Map<String, String> params = provider.getParams();
    HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
    for (Entry<String, String> entry : params.entrySet()) {
        String role = entry.getKey();
        String roleParams = entry.getValue();
        // Create the config based on whatever is specified at the provider level
        HaServiceConfig config = HaDescriptorFactory.createServiceConfig(role, roleParams);
        // Check for service-level param overrides
        Map<String, String> serviceLevelParams = null;
        for (Service s : topology.getServices()) {
            if (s.getRole().equals(role)) {
                serviceLevelParams = s.getParams();
                break;
            }
        }
        // Apply any service-level param overrides
        applyParamOverrides(config, serviceLevelParams);
        // Add the reconciled HA service config to the descriptor
        descriptor.addServiceConfig(config);
    }
    StringWriter writer = new StringWriter();
    try {
        HaDescriptorManager.store(descriptor, writer);
    } catch (IOException e) {
        LOG.failedToWriteHaDescriptor(e);
    }
    String asset = writer.toString();
    context.getWebArchive().addAsWebInfResource(new StringAsset(asset), HaServletContextListener.DESCRIPTOR_DEFAULT_FILE_NAME);
    context.addDescriptor(HA_DESCRIPTOR_NAME, descriptor);
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) StringWriter(java.io.StringWriter) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) IOException(java.io.IOException) HaDescriptor(org.apache.knox.gateway.ha.provider.HaDescriptor) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig)

Example 12 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig in project knox by apache.

the class DefaultHaDispatch method init.

@Override
public void init() {
    super.init();
    LOG.initializingForResourceRole(getServiceRole());
    if (haProvider != null) {
        HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(getServiceRole());
        maxFailoverAttempts = serviceConfig.getMaxFailoverAttempts();
        failoverSleep = serviceConfig.getFailoverSleep();
    }
}
Also used : HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig)

Example 13 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig in project knox by apache.

the class DefaultHaDescriptor method getEnabledServiceNames.

@Override
public List<String> getEnabledServiceNames() {
    ArrayList<String> services = new ArrayList<String>(serviceConfigs.size());
    Collection<HaServiceConfig> configs = serviceConfigs.values();
    for (HaServiceConfig config : configs) {
        if (config.isEnabled()) {
            services.add(config.getServiceName());
        }
    }
    return services;
}
Also used : ArrayList(java.util.ArrayList) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig)

Example 14 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig in project knox by apache.

the class RMHaDispatch method init.

@Override
public void init() {
    super.init();
    if (haProvider != null) {
        super.setResourceRole(RESOURCE_ROLE);
        HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(RESOURCE_ROLE);
        super.setMaxFailoverAttempts(serviceConfig.getMaxFailoverAttempts());
        super.setFailoverSleep(serviceConfig.getFailoverSleep());
        super.setMaxRetryAttempts(serviceConfig.getMaxRetryAttempts());
        super.setRetrySleep(serviceConfig.getRetrySleep());
        super.setHaProvider(haProvider);
    }
}
Also used : HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig)

Example 15 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig in project knox by apache.

the class RMUIHaDispatch method init.

@Override
public void init() {
    super.init();
    if (haProvider != null) {
        super.setResourceRole(RESOURCE_ROLE);
        HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(RESOURCE_ROLE);
        super.setMaxFailoverAttempts(serviceConfig.getMaxFailoverAttempts());
        super.setFailoverSleep(serviceConfig.getFailoverSleep());
        super.setMaxRetryAttempts(serviceConfig.getMaxRetryAttempts());
        super.setRetrySleep(serviceConfig.getRetrySleep());
        super.setHaProvider(haProvider);
    }
}
Also used : HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig)

Aggregations

HaServiceConfig (org.apache.knox.gateway.ha.provider.HaServiceConfig)20 Test (org.junit.Test)7 URLManager (org.apache.knox.gateway.ha.provider.URLManager)6 HaDescriptor (org.apache.knox.gateway.ha.provider.HaDescriptor)4 IOException (java.io.IOException)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)3 TestingCluster (org.apache.curator.test.TestingCluster)3 Before (org.junit.Before)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 Service (org.apache.knox.gateway.topology.Service)1 Topology (org.apache.knox.gateway.topology.Topology)1 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)1