Package org.apache.ambari.server.controller.internal

Examples of org.apache.ambari.server.controller.internal.URLStreamProvider


  }

  @Test
  public void testProxyDeleteRequest() throws Exception {
    ProxyService ps = new ProxyService();
    URLStreamProvider streamProviderMock = PowerMock.createNiceMock(URLStreamProvider.class);
    HttpURLConnection urlConnectionMock = createMock(HttpURLConnection.class);
    URI uriMock = PowerMock.createMock(URI.class);
    MultivaluedMap<String, String> headerParams = new MultivaluedMapImpl();
    Map<String, List<String>> headerParamsToForward = new HashMap<String, List<String>>();
    Response.ResponseBuilder responseBuilderMock = PowerMock.createMock(ResponseBuilderImpl.class);
    Response responseMock = createMock(ResponseImpl.class);
    headerParams.add("AmbariProxy-User-Remote","testuser");
    headerParams.add("Content-Type","testtype");
    List<String> userRemoteParams = new LinkedList<String>();
    userRemoteParams.add("testuser");
    headerParamsToForward.put("User-Remote", userRemoteParams);
    InputStream is = new ByteArrayInputStream("test".getBytes());
    PowerMock.mockStatic(Response.class);
    expect(getHttpHeaders().getRequestHeaders()).andReturn(headerParams);
    expect(getHttpHeaders().getRequestHeader("AmbariProxy-User-Remote")).andReturn(userRemoteParams);
    expect(getUriInfo().getRequestUri()).andReturn(uriMock);
    expect(uriMock.getQuery()).andReturn("url=testurl");
    expect(streamProviderMock.processURL("testurl", "DELETE", null, headerParamsToForward)).andReturn(urlConnectionMock);
    expect(urlConnectionMock.getResponseCode()).andReturn(200);
    expect(urlConnectionMock.getContentType()).andReturn("text/plain");
    expect(urlConnectionMock.getInputStream()).andReturn(is);
    PowerMock.expectNew(URLStreamProvider.class, 20000, 15000, null, null, null).andReturn(streamProviderMock);
    expect(Response.status(200)).andReturn(responseBuilderMock);
View Full Code Here


  }

  @Test
  public void testResponseWithError() throws Exception {
    ProxyService ps = new ProxyService();
    URLStreamProvider streamProviderMock = PowerMock.createNiceMock(URLStreamProvider.class);
    HttpURLConnection urlConnectionMock = createMock(HttpURLConnection.class);
    Response.ResponseBuilder responseBuilderMock = PowerMock.createMock(ResponseBuilderImpl.class);
    URI uriMock = PowerMock.createMock(URI.class);
    Response responseMock = createMock(ResponseImpl.class);
    InputStream es = new ByteArrayInputStream("error".getBytes());
    MultivaluedMap<String, String> headerParams = new MultivaluedMapImpl();
    Map<String, List<String>> headerParamsToForward = new HashMap<String, List<String>>();
    headerParams.add("AmbariProxy-User-Remote","testuser");
    headerParams.add("Content-Type","testtype");
    List<String> userRemoteParams = new LinkedList<String>();
    userRemoteParams.add("testuser");
    headerParamsToForward.put("User-Remote", userRemoteParams);
    PowerMock.mockStatic(Response.class);
    expect(getHttpHeaders().getRequestHeaders()).andReturn(headerParams);
    expect(getHttpHeaders().getRequestHeader("AmbariProxy-User-Remote")).andReturn(userRemoteParams);
    expect(getUriInfo().getRequestUri()).andReturn(uriMock);
    expect(uriMock.getQuery()).andReturn("url=testurl");
    expect(streamProviderMock.processURL("testurl", "GET", null, headerParamsToForward)).andReturn(urlConnectionMock);
    expect(urlConnectionMock.getResponseCode()).andReturn(400).times(2);
    expect(urlConnectionMock.getContentType()).andReturn("text/plain");
    expect(urlConnectionMock.getErrorStream()).andReturn(es);
    expect(Response.status(400)).andReturn(responseBuilderMock);
    expect(responseBuilderMock.entity(es)).andReturn(responseBuilderMock);
View Full Code Here

  }

  @Test
  public void testProxyWithJSONResponse() throws Exception {
    ProxyService ps = new ProxyService();
    URLStreamProvider streamProviderMock = PowerMock.createNiceMock(URLStreamProvider.class);
    HttpURLConnection urlConnectionMock = createMock(HttpURLConnection.class);
    URI uriMock = PowerMock.createMock(URI.class);
    MultivaluedMap<String, String> headerParams = new MultivaluedMapImpl();
    Map<String, List<String>> headerParamsToForward = new HashMap<String, List<String>>();
    Response.ResponseBuilder responseBuilderMock = PowerMock.createMock(ResponseBuilderImpl.class);
    Response responseMock = createMock(ResponseImpl.class);
    headerParams.add("AmbariProxy-User-Remote","testuser");
    headerParams.add("Content-Type","testtype");
    List<String> userRemoteParams = new LinkedList<String>();
    userRemoteParams.add("testuser");
    headerParamsToForward.put("User-Remote", userRemoteParams);
    Map map = new Gson().fromJson(new InputStreamReader(new ByteArrayInputStream("{ \"test\":\"test\" }".getBytes())), Map.class);
    PowerMock.mockStatic(Response.class);
    expect(getHttpHeaders().getRequestHeaders()).andReturn(headerParams);
    expect(getHttpHeaders().getRequestHeader("AmbariProxy-User-Remote")).andReturn(userRemoteParams);
    expect(getUriInfo().getRequestUri()).andReturn(uriMock);
    expect(uriMock.getQuery()).andReturn("url=testurl");
    expect(streamProviderMock.processURL("testurl", "GET", null, headerParamsToForward)).andReturn(urlConnectionMock);
    expect(urlConnectionMock.getResponseCode()).andReturn(200);
    expect(urlConnectionMock.getContentType()).andReturn("application/json");
    expect(urlConnectionMock.getInputStream()).andReturn(new ByteArrayInputStream("{ \"test\":\"test\" }".getBytes()));
    PowerMock.expectNew(URLStreamProvider.class, 20000, 15000, null, null, null).andReturn(streamProviderMock);
    expect(Response.status(200)).andReturn(responseBuilderMock);
View Full Code Here

  }

  @Test
  public void testEscapedURL() throws Exception {
    ProxyService ps = new ProxyService();
    URLStreamProvider streamProviderMock = PowerMock.createNiceMock(URLStreamProvider.class);
    MultivaluedMap<String, String> headerParams = new MultivaluedMapImpl();
    HttpURLConnection urlConnectionMock = createMock(HttpURLConnection.class);
    URI uri = UriBuilder.fromUri("http://dev01.hortonworks.com:8080/proxy?url=http%3a%2f%2fserver%3a8188%2fws%2fv1%2f" +
     "timeline%2fHIVE_QUERY_ID%3ffields=events%2cprimaryfilters%26limit=10%26primaryFilter=user%3ahiveuser1").build();
    Map<String, List<String>> headerParamsToForward = new HashMap<String, List<String>>();
    InputStream is = new ByteArrayInputStream("test".getBytes());
    List<String> userRemoteParams = new LinkedList<String>();
    userRemoteParams.add("testuser");
    headerParams.add("AmbariProxy-User-Remote","testuser");
    headerParams.add("Content-Type","testtype");
    headerParamsToForward.put("User-Remote", userRemoteParams);
    expect(getHttpHeaders().getRequestHeaders()).andReturn(headerParams);
    expect(getHttpHeaders().getRequestHeader("AmbariProxy-User-Remote")).andReturn(userRemoteParams);
    expect(getUriInfo().getRequestUri()).andReturn(uri);
    expect(urlConnectionMock.getResponseCode()).andReturn(200);
    expect(urlConnectionMock.getContentType()).andReturn("text/plain");
    expect(urlConnectionMock.getInputStream()).andReturn(is);
    PowerMock.expectNew(URLStreamProvider.class, 20000, 15000, null, null, null).andReturn(streamProviderMock);
    expect(streamProviderMock.processURL("http://server:8188/ws/v1/timeline/HIVE_QUERY_ID?fields=events,primary" +
     "filters&limit=10&primaryFilter=user:hiveuser1", "GET", null, headerParamsToForward)).andReturn(urlConnectionMock);
    PowerMock.replay(streamProviderMock, URLStreamProvider.class);
    replay(getUriInfo(), urlConnectionMock, getHttpHeaders());
    ps.processGetRequestForwarding(getHttpHeaders(),getUriInfo());
View Full Code Here

  }

  @Test
  public void testViewURLStreamProvider() throws Exception {

    URLStreamProvider streamProvider = createNiceMock(URLStreamProvider.class);
    HttpURLConnection urlConnection = createNiceMock(HttpURLConnection.class);
    InputStream inputStream = createNiceMock(InputStream.class);

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("header", "headerValue");

    Map<String, List<String>> headerMap = new HashMap<String, List<String>>();
    headerMap.put("header", Collections.singletonList("headerValue"));

    expect(streamProvider.processURL("spec", "requestMethod", "params", headerMap)).andReturn(urlConnection);
    expect(urlConnection.getInputStream()).andReturn(inputStream);

    replay(streamProvider, urlConnection, inputStream);

    ViewContextImpl.ViewURLStreamProvider viewURLStreamProvider =
View Full Code Here

        if (!rr.isVerifyBaseUrl()) {
          ambariMetaInfo.updateRepoBaseURL(rr.getStackName(),
              rr.getStackVersion(), rr.getOsType(), rr.getRepoId(),
              rr.getBaseUrl());
        } else {
          URLStreamProvider usp = new URLStreamProvider(REPO_URL_CONNECT_TIMEOUT,
              REPO_URL_READ_TIMEOUT, null, null, null);

          boolean bFound = false;
         
          String[] suffixes = configs.getRepoValidationSuffixes(rr.getOsType());
          for (int i = 0; i < suffixes.length && !bFound; i++) {
            String suffix = suffixes[i];
            String spec = rr.getBaseUrl();
           
            if (spec.charAt(spec.length()-1) != '/' && suffix.charAt(0) != '/')
              spec = rr.getBaseUrl() + "/" + suffix;
            else if (spec.charAt(spec.length()-1) == '/' && suffix.charAt(0) == '/')
              spec = rr.getBaseUrl() + suffix.substring(1);
            else
              spec = rr.getBaseUrl() + suffix;
           
            try {
              IOUtils.readLines(usp.readFrom(spec));
              bFound = true;
            } catch (IOException ioe) {
              LOG.error("IOException loading the base URL", ioe);
            }
          }
View Full Code Here

    Map<String, Map<String, Object>> latestUrlMap = null;
   
    try {
      if (sourceUri.startsWith("http")) {
       
        URLStreamProvider streamProvider = new URLStreamProvider(
            LOOKUP_CONNECTION_TIMEOUT, LOOKUP_READ_TIMEOUT,
            null, null, null);
       
        LOG.info("Loading latest URL info from " + sourceUri);
        latestUrlMap = gson.fromJson(new InputStreamReader(
            streamProvider.readFrom(sourceUri)), type);
      } else {
        File jsonFile = null;
        if (sourceUri.charAt(0) == '.') {
          jsonFile = new File(stackRepoFolder, sourceUri);
        } else {
View Full Code Here

        if (!rr.isVerifyBaseUrl()) {
          ambariMetaInfo.updateRepoBaseURL(rr.getStackName(),
              rr.getStackVersion(), rr.getOsType(), rr.getRepoId(),
              rr.getBaseUrl());
        } else {
          URLStreamProvider usp = new URLStreamProvider(REPO_URL_CONNECT_TIMEOUT,
              REPO_URL_READ_TIMEOUT, null, null, null);

          boolean bFound = false;
         
          String[] suffixes = configs.getRepoValidationSuffixes();
          for (int i = 0; i < suffixes.length && !bFound; i++) {
            String suffix = suffixes[i];
            String spec = rr.getBaseUrl();
           
            if (spec.charAt(spec.length()-1) != '/' && suffix.charAt(0) != '/')
              spec = rr.getBaseUrl() + "/" + suffix;
            else if (spec.charAt(spec.length()-1) == '/' && suffix.charAt(0) == '/')
              spec = rr.getBaseUrl() + suffix.substring(1);
            else
              spec = rr.getBaseUrl() + suffix;
           
            try {
              IOUtils.readLines(usp.readFrom(spec));
              bFound = true;
            } catch (IOException ioe) {
              // failed, but try other suffixes
            }
          }
View Full Code Here

        if (!rr.isVerifyBaseUrl()) {
          ambariMetaInfo.updateRepoBaseURL(rr.getStackName(),
              rr.getStackVersion(), rr.getOsType(), rr.getRepoId(),
              rr.getBaseUrl());
        } else {
          URLStreamProvider usp = new URLStreamProvider(REPO_URL_CONNECT_TIMEOUT,
              REPO_URL_READ_TIMEOUT, null, null, null);

          boolean bFound = false;
         
          String[] suffixes = configs.getRepoValidationSuffixes();
          for (int i = 0; i < suffixes.length && !bFound; i++) {
            String suffix = suffixes[i];
            String spec = rr.getBaseUrl();
           
            if (spec.charAt(spec.length()-1) != '/' && suffix.charAt(0) != '/')
              spec = rr.getBaseUrl() + "/" + suffix;
            else if (spec.charAt(spec.length()-1) == '/' && suffix.charAt(0) == '/')
              spec = rr.getBaseUrl() + suffix.substring(1);
            else
              spec = rr.getBaseUrl() + suffix;
           
            try {
              IOUtils.readLines(usp.readFrom(spec));
              bFound = true;
            } catch (IOException ioe) {
              // failed, but try other suffixes
            }
          }
View Full Code Here

  }

  @Test
  public void testViewURLStreamProvider() throws Exception {

    URLStreamProvider streamProvider = createNiceMock(URLStreamProvider.class);
    HttpURLConnection urlConnection = createNiceMock(HttpURLConnection.class);
    InputStream inputStream = createNiceMock(InputStream.class);

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("header", "headerValue");

    Map<String, List<String>> headerMap = new HashMap<String, List<String>>();
    headerMap.put("header", Collections.singletonList("headerValue"));

    expect(streamProvider.processURL("spec", "requestMethod", "params", headerMap)).andReturn(urlConnection);
    expect(urlConnection.getInputStream()).andReturn(inputStream);

    replay(streamProvider, urlConnection, inputStream);

    ViewContextImpl.ViewURLStreamProvider viewURLStreamProvider =
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.controller.internal.URLStreamProvider

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.