Package org.apache.hadoop.gateway.ha.provider

Examples of org.apache.hadoop.gateway.ha.provider.HaServiceConfig


            "<service name='bar' failoverLimit='3' enabled='true'/></ha>";
      ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes());
      HaDescriptor descriptor = HaDescriptorManager.load(inputStream);
      assertNotNull(descriptor);
      assertEquals(1, descriptor.getEnabledServiceNames().size());
      HaServiceConfig config =  descriptor.getServiceConfig("foo");
      assertNotNull(config);
      assertEquals("foo", config.getServiceName());
      assertEquals(42, config.getMaxFailoverAttempts());
      assertEquals(4000, config.getFailoverSleep());
      assertEquals(2, config.getMaxRetryAttempts());
      assertEquals(2213, config.getRetrySleep());
      assertFalse(config.isEnabled());
      config =  descriptor.getServiceConfig("bar");
      assertTrue(config.isEnabled());
   }
View Full Code Here


      String xml = "<ha><service name='foo'/></ha>";
      ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes());
      HaDescriptor descriptor = HaDescriptorManager.load(inputStream);
      assertNotNull(descriptor);
      assertEquals(1, descriptor.getEnabledServiceNames().size());
      HaServiceConfig config =  descriptor.getServiceConfig("foo");
      assertNotNull(config);
      assertEquals("foo", config.getServiceName());
      assertEquals(HaServiceConfigConstants.DEFAULT_MAX_FAILOVER_ATTEMPTS, config.getMaxFailoverAttempts());
      assertEquals(HaServiceConfigConstants.DEFAULT_FAILOVER_SLEEP, config.getFailoverSleep());
      assertEquals(HaServiceConfigConstants.DEFAULT_MAX_RETRY_ATTEMPTS, config.getMaxRetryAttempts());
      assertEquals(HaServiceConfigConstants.DEFAULT_RETRY_SLEEP, config.getRetrySleep());
      assertEquals(HaServiceConfigConstants.DEFAULT_ENABLED, config.isEnabled());
   }
View Full Code Here

   @Override
   public void contributeProvider(DeploymentContext context, Provider provider) {
      Map<String, String> params = provider.getParams();
      HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
      for (Entry<String, String> entry : params.entrySet()) {
         HaServiceConfig config = HaDescriptorFactory.createServiceConfig(entry.getKey(), entry.getValue());
         descriptor.addServiceConfig(config);
      }
      StringWriter writer = new StringWriter();
      try {
         HaDescriptorManager.store(descriptor, writer);
View Full Code Here

         Document document = builder.parse(inputStream);
         NodeList nodeList = document.getElementsByTagName(SERVICE_ELEMENT);
         if (nodeList != null && nodeList.getLength() > 0) {
            for (int i = 0; i < nodeList.getLength(); i++) {
               Element element = (Element) nodeList.item(i);
               HaServiceConfig config = HaDescriptorFactory.createServiceConfig(element.getAttribute(SERVICE_NAME_ATTRIBUTE),
                     element.getAttribute(ENABLED_ATTRIBUTE),
                     element.getAttribute(MAX_FAILOVER_ATTEMPTS),
                     element.getAttribute(FAILOVER_SLEEP),
                     element.getAttribute(MAX_RETRY_ATTEMPTS),
                     element.getAttribute(RETRY_SLEEP));
View Full Code Here

      haServices.put(serviceName, new URLManager(urls));
   }

   @Override
   public boolean isHaEnabled(String serviceName) {
      HaServiceConfig config = descriptor.getServiceConfig(serviceName);
      if (config != null && config.isEnabled()) {
         return true;
      }
      return false;
   }
View Full Code Here

      assertNotNull(HaDescriptorFactory.createDescriptor());
   }

   @Test
   public void testCreateServiceConfig() {
      HaServiceConfig serviceConfig = HaDescriptorFactory.createServiceConfig("foo", "enabled=true;maxFailoverAttempts=42;failoverSleep=50;maxRetryAttempts=1;retrySleep=1000");
      assertNotNull(serviceConfig);
      assertTrue(serviceConfig.isEnabled());
      assertEquals("foo", serviceConfig.getServiceName());
      assertEquals(42, serviceConfig.getMaxFailoverAttempts());
      assertEquals(50, serviceConfig.getFailoverSleep());
      assertEquals(1, serviceConfig.getMaxRetryAttempts());
      assertEquals(1000, serviceConfig.getRetrySleep());

      serviceConfig = HaDescriptorFactory.createServiceConfig("bar", "false", "3", "1000", "5", "3000");
      assertNotNull(serviceConfig);
      assertFalse(serviceConfig.isEnabled());
      assertEquals("bar", serviceConfig.getServiceName());
      assertEquals(3, serviceConfig.getMaxFailoverAttempts());
      assertEquals(1000, serviceConfig.getFailoverSleep());
      assertEquals(5, serviceConfig.getMaxRetryAttempts());
      assertEquals(3000, serviceConfig.getRetrySleep());

   }
View Full Code Here

   public void init(FilterConfig filterConfig) throws ServletException {
      super.init(filterConfig);
      resourceRole = filterConfig.getInitParameter(RESOURCE_ROLE_ATTRIBUTE);
      LOG.initializingForResourceRole(resourceRole);
      haProvider = HaServletContextListener.getHaProvider(filterConfig.getServletContext());
      HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(resourceRole);
      maxFailoverAttempts = serviceConfig.getMaxFailoverAttempts();
      failoverSleep = serviceConfig.getFailoverSleep();
      maxRetryAttempts = serviceConfig.getMaxRetryAttempts();
      retrySleep = serviceConfig.getRetrySleep();
   }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.gateway.ha.provider.HaServiceConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.