Package org.apache.ambari.server.state

Examples of org.apache.ambari.server.state.RepositoryInfo


          String mirrorsList = getTagValue(REPOSITORY_XML_PROPERTY_MIRRORSLIST, property);

          String[] osTypes = osType.split(",");

          for (String os : osTypes) {
            RepositoryInfo repositoryInfo = new RepositoryInfo();
            repositoryInfo.setOsType(os.trim());
            repositoryInfo.setRepoId(repoId);
            repositoryInfo.setRepoName(repoName);
            repositoryInfo.setBaseUrl(baseUrl);
            repositoryInfo.setDefaultBaseUrl(baseUrl);
            repositoryInfo.setMirrorsList(mirrorsList);
           
            if (LOG.isDebugEnabled()) {
              LOG.debug("Adding repo to stack"
                  + ", repoInfo=" + repositoryInfo.toString());
            }

            if (null != metainfoDAO) {
              LOG.debug("Checking for override for base_url");
              String key = generateRepoMetaKey(repoName, stackVersion, os, repoId, REPOSITORY_XML_PROPERTY_BASEURL);
              MetainfoEntity entity = metainfoDAO.findByKey(key);
              if (null != entity) {
                repositoryInfo.setBaseUrl(entity.getMetainfoValue());
              }
             
            }           
           
            repositorysInfo.add(repositoryInfo);
View Full Code Here


   */
  public void updateRepoBaseURL(String stackName,
      String stackVersion, String osType, String repoId, String newBaseUrl) throws AmbariException {

    // validate existing
    RepositoryInfo ri = getRepository(stackName, stackVersion, osType, repoId);
   
    if (!stackRoot.exists())
      throw new StackAccessException("Stack root does not exist.");
   
    ri.setBaseUrl(newBaseUrl);
   
    if (null != metainfoDAO) {
      String metaKey = generateRepoMetaKey(stackName, stackVersion, osType,
          repoId, REPOSITORY_XML_PROPERTY_BASEURL);
     
      MetainfoEntity entity = new MetainfoEntity();
      entity.setMetainfoName(metaKey);
      entity.setMetainfoValue(newBaseUrl);
     
      if (null != ri.getDefaultBaseUrl() && newBaseUrl.equals(ri.getDefaultBaseUrl())) {
        metainfoDAO.remove(entity);
      } else {
        metainfoDAO.merge(entity);
      }
    }
View Full Code Here

 
  @Test
  public void testUpdateRepoUrl() throws Exception {
    String INCORRECT_URL_2 = "http://bar.com/foo";
   
    RepositoryInfo repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertNotNull(repo);
    assertNotNull(repo.getBaseUrl());
   
    String original = repo.getBaseUrl();
   
    repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertEquals(original, repo.getBaseUrl());
   
    ambariMetaInfo.updateRepoBaseURL(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID, INCORRECT_BASE_URL);
   
    repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertEquals(INCORRECT_BASE_URL, repo.getBaseUrl());
    assertEquals(original, repo.getDefaultBaseUrl());
   
    ambariMetaInfo.updateRepoBaseURL(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID, INCORRECT_URL_2);
    repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertFalse(INCORRECT_BASE_URL.equals(repo.getBaseUrl()));
    assertEquals(INCORRECT_URL_2, repo.getBaseUrl());
    assertEquals(original, repo.getDefaultBaseUrl());

    // verify change with new meta info
    AmbariMetaInfo ami = new AmbariMetaInfo(new File("src/test/resources/stacks"), new File("target/version"));
    injector.injectMembers(ami);
    ami.init();
   
    repo = ami.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertEquals(INCORRECT_URL_2, repo.getBaseUrl());
    assertNotNull(repo.getDefaultBaseUrl());
    assertEquals(original, repo.getDefaultBaseUrl());
   
    ami.updateRepoBaseURL(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID, original);
    repo = ami.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertEquals(original, repo.getBaseUrl());
    assertEquals(original, repo.getDefaultBaseUrl());
  }
View Full Code Here

      for (RepositoryInfo repository: repositories) {
        response.add(repository.convertToResponse());
      }

    } else {
      RepositoryInfo repository = this.ambariMetaInfo.getRepository(stackName, stackVersion, osType, repoId);
      response = Collections.singleton(repository.convertToResponse());
    }
   
    return response;
  }
View Full Code Here

      throw new StackAccessException("stackName=" + stackName
          + ", stackVersion=" + version
          + ", osType=" + osType
          + ", repoId=" + repoId);

    RepositoryInfo repoResult = null;
    for (RepositoryInfo repository : repositories) {
      if (repository.getRepoId().equals(repoId))
        repoResult = repository;
    }
    if (repoResult == null)
View Full Code Here

    List<RepositoryInfo> list = new ArrayList<RepositoryInfo>();

    for (Os o : rxml.getOses()) {
      for (String os : o.getType().split(",")) {
        for (Repo r : o.getRepos()) {
          RepositoryInfo ri = new RepositoryInfo();
          ri.setBaseUrl(r.getBaseUrl());
          ri.setDefaultBaseUrl(r.getBaseUrl());
          ri.setMirrorsList(r.getMirrorsList());
          ri.setOsType(os.trim());
          ri.setRepoId(r.getRepoId());
          ri.setRepoName(r.getRepoName());

          if (null != metainfoDAO) {
            LOG.debug("Checking for override for base_url");
            String key = generateRepoMetaKey(r.getRepoName(), stackVersion,
                o.getType(), r.getRepoId(), REPOSITORY_XML_PROPERTY_BASEURL);
            MetainfoEntity entity = metainfoDAO.findByKey(key);
            if (null != entity) {
              ri.setBaseUrl(entity.getMetainfoValue());
            }
          }

          if (LOG.isDebugEnabled()) {
            LOG.debug("Adding repo to stack"
                + ", repoInfo=" + ri.toString());
          }

          list.add(ri);
        }
      }
View Full Code Here

   */
  public void updateRepoBaseURL(String stackName,
      String stackVersion, String osType, String repoId, String newBaseUrl) throws AmbariException {

    // validate existing
    RepositoryInfo ri = getRepository(stackName, stackVersion, osType, repoId);

    if (!stackRoot.exists())
      throw new StackAccessException("Stack root does not exist.");

    ri.setBaseUrl(newBaseUrl);

    if (null != metainfoDAO) {
      String metaKey = generateRepoMetaKey(stackName, stackVersion, osType,
          repoId, REPOSITORY_XML_PROPERTY_BASEURL);

      MetainfoEntity entity = new MetainfoEntity();
      entity.setMetainfoName(metaKey);
      entity.setMetainfoValue(newBaseUrl);

      if (null != ri.getDefaultBaseUrl() && newBaseUrl.equals(ri.getDefaultBaseUrl())) {
        metainfoDAO.remove(entity);
      } else {
        metainfoDAO.merge(entity);
      }
    }
View Full Code Here

 
  @Test
  public void testUpdateRepoUrl() throws Exception {
    String INCORRECT_URL_2 = "http://bar.com/foo";
   
    RepositoryInfo repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertNotNull(repo);
    assertNotNull(repo.getBaseUrl());
   
    String original = repo.getBaseUrl();
   
    repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertEquals(original, repo.getBaseUrl());
   
    ambariMetaInfo.updateRepoBaseURL(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID, INCORRECT_BASE_URL);
   
    repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertEquals(INCORRECT_BASE_URL, repo.getBaseUrl());
    assertEquals(original, repo.getDefaultBaseUrl());
   
    ambariMetaInfo.updateRepoBaseURL(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID, INCORRECT_URL_2);
    repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertFalse(INCORRECT_BASE_URL.equals(repo.getBaseUrl()));
    assertEquals(INCORRECT_URL_2, repo.getBaseUrl());
    assertEquals(original, repo.getDefaultBaseUrl());

    // verify change with new meta info
    AmbariMetaInfo ami = new AmbariMetaInfo(new File("src/test/resources/stacks"), new File("target/version"));
    injector.injectMembers(ami);
    ami.init();
   
    repo = ami.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertEquals(INCORRECT_URL_2, repo.getBaseUrl());
    assertNotNull(repo.getDefaultBaseUrl());
    assertEquals(original, repo.getDefaultBaseUrl());
   
    ami.updateRepoBaseURL(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID, original);
    repo = ami.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    assertEquals(original, repo.getBaseUrl());
    assertEquals(original, repo.getDefaultBaseUrl());
  }
View Full Code Here

    assertEquals(original, repo.getDefaultBaseUrl());
  }
 
  @Ignore
  public void testUpdateRepoUrlController() throws Exception {
    RepositoryInfo repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
   
    RepositoryRequest request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    request.setBaseUrl("http://hortonworks.com");
   
    Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>();
    requests.add(request);
   
    // test bad url
    try {
      controller.updateRespositories(requests);
      fail ("Expected exception on invalid url");
    } catch (Exception e) {
    }
   
    // test bad url, but allow to set anyway
    request.setVerifyBaseUrl(false);
    controller.updateRespositories(requests);
    Assert.assertEquals(request.getBaseUrl(), repo.getBaseUrl());

    // reset repo
    requests.clear();
    request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
    request.setBaseUrl(repo.getDefaultBaseUrl());
    requests.add(request);
    controller.updateRespositories(requests);
    Assert.assertEquals(repo.getBaseUrl(), repo.getDefaultBaseUrl());

    String baseUrl = repo.getDefaultBaseUrl();
    if (!baseUrl.endsWith("/"))
      baseUrl += "/";
   
    // variation #1: url with trailing slash, suffix preceding slash
    backingProperties.setProperty(Configuration.REPO_SUFFIX_KEY, "/repodata/repomd.xml");
    Assert.assertTrue(baseUrl.endsWith("/") && configuration.getRepoValidationSuffixes()[0].startsWith("/"));
    request.setBaseUrl(baseUrl);
    controller.updateRespositories(requests);
    Assert.assertEquals(baseUrl, repo.getBaseUrl());

    // variation #2: url with trailing slash, suffix no preceding slash
    backingProperties.setProperty(Configuration.REPO_SUFFIX_KEY, "repodata/repomd.xml");
    Assert.assertTrue(baseUrl.endsWith("/") && !configuration.getRepoValidationSuffixes()[0].startsWith("/"));
    request.setBaseUrl(baseUrl);
    controller.updateRespositories(requests);
    Assert.assertEquals(baseUrl, repo.getBaseUrl());

    baseUrl = baseUrl.substring(0, baseUrl.length()-1);
    // variation #3: url with no trailing slash, suffix no prededing slash   
    Assert.assertTrue(!baseUrl.endsWith("/") && !configuration.getRepoValidationSuffixes()[0].startsWith("/"));
    request.setBaseUrl(baseUrl);
    controller.updateRespositories(requests);
    Assert.assertEquals(baseUrl, repo.getBaseUrl());
   
    // variation #4: url with no trailing slash, suffix preceding slash
    backingProperties.setProperty(Configuration.REPO_SUFFIX_KEY, "/repodata/repomd.xml");
    Assert.assertTrue(!baseUrl.endsWith("/") && configuration.getRepoValidationSuffixes()[0].startsWith("/"));
    request.setBaseUrl(baseUrl);
    controller.updateRespositories(requests);
    Assert.assertEquals(baseUrl, repo.getBaseUrl());
   
    // variation #5: multiple suffix tests
    backingProperties.setProperty(Configuration.REPO_SUFFIX_KEY, "/foo/bar.xml,/repodata/repomd.xml");
    Assert.assertTrue(configuration.getRepoValidationSuffixes().length > 1);
    request.setBaseUrl(baseUrl);
    controller.updateRespositories(requests);
    Assert.assertEquals(baseUrl, repo.getBaseUrl());
   
  }
View Full Code Here

    Assert.assertEquals(repositories.size(), REPOS_CNT);
  }

  @Test
  public void testGetRepository() throws Exception {
    RepositoryInfo repository = metaInfo.getRepository(STACK_NAME_HDP, STACK_VERSION_HDP, OS_TYPE, REPO_ID);
    Assert.assertEquals(repository.getRepoId(), REPO_ID);

    try {
      metaInfo.getRepository(STACK_NAME_HDP, STACK_VERSION_HDP, OS_TYPE, NON_EXT_VALUE);
    } catch (StackAccessException e) {
      Assert.assertTrue(e instanceof StackAccessException);
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.state.RepositoryInfo

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.