Examples of HaDescriptor


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

   @Test
   public void testDescriptorLoad() throws IOException {
      String xml = "<ha><service name='foo' maxFailoverAttempts='42' failoverSleep='4000' maxRetryAttempts='2' retrySleep='2213' enabled='false'/>" +
            "<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

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

   @Test
   public void testDescriptorDefaults() throws IOException {
      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());
View Full Code Here

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

      assertEquals(HaServiceConfigConstants.DEFAULT_ENABLED, config.isEnabled());
   }

   @Test
   public void testDescriptorStoring() throws IOException {
      HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
      descriptor.addServiceConfig(HaDescriptorFactory.createServiceConfig("foo", "false", "42", "1000", "3", "3000"));
      descriptor.addServiceConfig(HaDescriptorFactory.createServiceConfig("bar", "true", "3", "5000", "5", "8000"));
      StringWriter writer = new StringWriter();
      HaDescriptorManager.store(descriptor, writer);
      String descriptorXml = writer.toString();
      String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
            "<ha>\n" +
View Full Code Here

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

   }

   @Test
   public void testConnectivityFailover() throws Exception {
      String serviceName = "WEBHDFS";
      HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
      descriptor.addServiceConfig(HaDescriptorFactory.createServiceConfig(serviceName, "true", "1", "1000", "2", "1000"));
      HaProvider provider = new DefaultHaProvider(descriptor);
      URI uri1 = new URI( "http://unreachable-host" );
      URI uri2 = new URI( "http://reachable-host" );
      ArrayList<String> urlList = new ArrayList<String>();
      urlList.add(uri1.toString());
View Full Code Here

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

   }

   @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);
      } catch (IOException e) {
View Full Code Here

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

         throw new IOException(e);
      }
   }

   public static HaDescriptor load(InputStream inputStream) throws IOException {
      HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
      DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
      try {
         DocumentBuilder builder = builderFactory.newDocumentBuilder();
         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));
               descriptor.addServiceConfig(config);
            }
         }
      } catch (ParserConfigurationException e) {
         LOG.failedToLoadHaDescriptor(e);
         throw new IOException(e);
View Full Code Here

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

      try {
         new DefaultHaProvider(null);
         fail("provider construction should have failed with null descriptor");
      } catch (IllegalArgumentException e) {
      }
      HaDescriptor descriptor = new DefaultHaDescriptor();
      HaProvider provider = new DefaultHaProvider(descriptor);
      assertNotNull(provider.getHaDescriptor());
      descriptor.addServiceConfig(new DefaultHaServiceConfig("foo"));
      assertTrue(provider.isHaEnabled("foo"));
   }
View Full Code Here

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

      assertTrue(provider.isHaEnabled("foo"));
   }

   @Test
   public void testAddingService() {
      HaDescriptor descriptor = new DefaultHaDescriptor();
      HaProvider provider = new DefaultHaProvider(descriptor);
      ArrayList<String> urls = new ArrayList<String>();
      urls.add("http://host1");
      urls.add("http://host2");
      provider.addHaService("foo", urls);
View Full Code Here

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

      assertThat(url, isIn(urls));
   }

   @Test
   public void testActiveUrl() {
      HaDescriptor descriptor = new DefaultHaDescriptor();
      HaProvider provider = new DefaultHaProvider(descriptor);
      ArrayList<String> urls = new ArrayList<String>();
      String url1 = "http://host1";
      urls.add(url1);
      String url2 = "http://host2";
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.