Java Code Examples for com.ctrip.framework.apollo.core.ConfigConsts#NAMESPACE_APPLICATION

The following examples show how to use com.ctrip.framework.apollo.core.ConfigConsts#NAMESPACE_APPLICATION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReleaseOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName,
    NamespaceReleaseDTO releaseDTO) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(releaseDTO.getReleaseTitle(), "Release title");
  checkNotEmpty(releaseDTO.getReleasedBy(), "Released by");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = post(path, releaseDTO)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Release namespace: %s for appId: %s, cluster: %s in env: %s failed", namespaceName, appId,
            clusterName, env), ex);
  }
}
 
Example 2
Source File: DefaultConfigServiceTest.java    From apollo with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  configService = new DefaultConfigService();
  ReflectionTestUtils.setField(configService, "releaseService", releaseService);
  ReflectionTestUtils.setField(configService, "grayReleaseRulesHolder", grayReleaseRulesHolder);

  someClientAppId = "1234";
  someConfigAppId = "1";
  someClusterName = "someClusterName";
  defaultClusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  someDataCenter = "someDC";
  someClientIp = "someClientIp";

  when(grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule(anyString(), anyString(),
      anyString(), anyString(), anyString())).thenReturn(null);
}
 
Example 3
Source File: NamespaceHandler.java    From apollo with Apache License 2.0 6 votes vote down vote up
@Override
protected void doParse(Element element, BeanDefinitionBuilder builder) {
  String namespaces = element.getAttribute("namespaces");
  //default to application
  if (Strings.isNullOrEmpty(namespaces)) {
    namespaces = ConfigConsts.NAMESPACE_APPLICATION;
  }

  int order = Ordered.LOWEST_PRECEDENCE;
  String orderAttribute = element.getAttribute("order");

  if (!Strings.isNullOrEmpty(orderAttribute)) {
    try {
      order = Integer.parseInt(orderAttribute);
    } catch (Throwable ex) {
      throw new IllegalArgumentException(
          String.format("Invalid order: %s for namespaces: %s", orderAttribute, namespaces));
    }
  }
  PropertySourcesProcessor.addNamespaces(NAMESPACE_SPLITTER.splitToList(namespaces), order);
}
 
Example 4
Source File: NamespaceOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName, String namespaceName) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/lock", escapePath(env), escapePath(appId),
      escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = get(path)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenNamespaceLockDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Get namespace lock for appId: %s, cluster: %s, namespace: %s in env: %s failed", appId, clusterName,
            namespaceName, env), ex);
  }
}
 
Example 5
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public void removeItem(String appId, String env, String clusterName, String namespaceName, String key, String operator) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(key, "Item key");
  checkNotEmpty(operator, "Operator");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s?operator=%s",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key),
      escapeParam(operator));

  try (CloseableHttpResponse ignored = delete(path)) {
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Remove item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId,
            clusterName, namespaceName, env), ex);
  }

}
 
Example 6
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public void updateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(itemDTO.getKey(), "Item key");
  checkNotEmpty(itemDTO.getDataChangeLastModifiedBy(), "Item modified by");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName),
      escapePath(itemDTO.getKey()));

  try (CloseableHttpResponse ignored = put(path, itemDTO)) {
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Update item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", itemDTO.getKey(),
            appId, clusterName, namespaceName, env), ex);
  }
}
 
Example 7
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(itemDTO.getKey(), "Item key");
  checkNotEmpty(itemDTO.getDataChangeCreatedBy(), "Item created by");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = post(path, itemDTO)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Create item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", itemDTO.getKey(),
            appId, clusterName, namespaceName, env), ex);
  }
}
 
Example 8
Source File: ReleaseOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenReleaseDTO getLatestActiveRelease(String appId, String env, String clusterName, String namespaceName) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases/latest",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = get(path)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Get latest active release for appId: %s, cluster: %s, namespace: %s in env: %s failed", appId,
            clusterName, namespaceName, env), ex);
  }
}
 
Example 9
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 5 votes vote down vote up
public void createOrUpdateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(itemDTO.getKey(), "Item key");
  checkNotEmpty(itemDTO.getDataChangeCreatedBy(), "Item created by");

  if (Strings.isNullOrEmpty(itemDTO.getDataChangeLastModifiedBy())) {
    itemDTO.setDataChangeLastModifiedBy(itemDTO.getDataChangeCreatedBy());
  }

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s?createIfNotExists=true",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName),
      escapePath(itemDTO.getKey()));

  try (CloseableHttpResponse ignored = put(path, itemDTO)) {
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("CreateOrUpdate item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", itemDTO.getKey(),
            appId, clusterName, namespaceName, env), ex);
  }
}
 
Example 10
Source File: NotificationControllerIntegrationTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ReflectionTestUtils.invokeMethod(releaseMessageServiceWithCache, "reset");
  ReflectionTestUtils.invokeMethod(appNamespaceServiceWithCache, "reset");
  someAppId = "someAppId";
  someCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
  somePublicNamespace = "somePublicNamespace";
  executorService = Executors.newSingleThreadExecutor();
}
 
Example 11
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 5 votes vote down vote up
public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(key, "Item key");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key));

  try (CloseableHttpResponse response = get(path)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class);
  } catch (Throwable ex) {
    // return null if item doesn't exist
    if (ex instanceof ApolloOpenApiException && ((ApolloOpenApiException)ex).getStatus() == 404) {
      return null;
    }
    throw new RuntimeException(String
        .format("Get item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId, clusterName,
            namespaceName, env), ex);
  }
}
 
Example 12
Source File: SpringBootApolloRefreshConfig.java    From apollo with Apache License 2.0 5 votes vote down vote up
@ApolloConfigChangeListener(value = {ConfigConsts.NAMESPACE_APPLICATION, "TEST1.apollo", "application.yaml"},
    interestedKeyPrefixes = {"redis.cache."})
public void onChange(ConfigChangeEvent changeEvent) {
  logger.info("before refresh {}", sampleRedisConfig.toString());
  refreshScope.refresh("sampleRedisConfig");
  logger.info("after refresh {}", sampleRedisConfig.toString());
}
 
Example 13
Source File: NotificationControllerV2Test.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  gson = new Gson();
  controller = new NotificationControllerV2(
      watchKeysUtil, releaseMessageService, entityManagerUtil, namespaceUtil, gson, bizConfig
  );

  when(bizConfig.releaseMessageNotificationBatch()).thenReturn(100);
  when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(5);

  someAppId = "someAppId";
  someCluster = "someCluster";
  defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
  somePublicNamespace = "somePublicNamespace";
  someDataCenter = "someDC";
  someNotificationId = 1;
  someClientIp = "someClientIp";

  when(namespaceUtil.filterNamespaceName(defaultNamespace)).thenReturn(defaultNamespace);
  when(namespaceUtil.filterNamespaceName(somePublicNamespace)).thenReturn(somePublicNamespace);
  when(namespaceUtil.normalizeNamespace(someAppId, defaultNamespace)).thenReturn(defaultNamespace);
  when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespace)).thenReturn(somePublicNamespace);

  deferredResults =
      (Multimap<String, DeferredResultWrapper>) ReflectionTestUtils.getField(controller, "deferredResults");
}
 
Example 14
Source File: NotificationControllerV2IntegrationTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ReflectionTestUtils.invokeMethod(releaseMessageServiceWithCache, "reset");
  someAppId = "someAppId";
  someCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
  somePublicNamespace = "somePublicNamespace";
  executorService = Executors.newSingleThreadExecutor();
  typeReference = new ParameterizedTypeReference<List<ApolloConfigNotification>>() {
  };
}
 
Example 15
Source File: ApolloConfig.java    From java-tutorial with MIT License 5 votes vote down vote up
@ApolloConfigChangeListener(ConfigConsts.NAMESPACE_APPLICATION)
public void onChange(ConfigChangeEvent changeEvent) {
    logger.info("before refresh");
    for (String changedKey : changeEvent.changedKeys()) {
        logger.info("===============================================================");
        logger.info("changedKey:{} value:{}", changedKey, changeEvent.getChange(changedKey));
        ConfigChange configChange = changeEvent.getChange(changedKey);
        configChange.getOldValue();
    }
    refreshScope.refreshAll();
    logger.info("after refresh");
}
 
Example 16
Source File: ConfigIntegrationTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  super.setUp();

  defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
  someOtherNamespace = "someOtherNamespace";
  someReleaseKey = "1";
  configDir = new File(ClassLoaderUtil.getClassPath() + "config-cache");
  if (configDir.exists()) {
    configDir.delete();
  }
  configDir.mkdirs();
  remoteConfigLongPollService = ApolloInjector.getInstance(RemoteConfigLongPollService.class);
}
 
Example 17
Source File: ConfigServiceTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompareTargetNamespaceHasNoItems() {
  ItemDTO sourceItem1 = new ItemDTO("a", "b", "comment", 1);
  List<ItemDTO> sourceItems = Arrays.asList(sourceItem1);

  String appId = "6666", env = "LOCAL", clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT,
      namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  List<NamespaceIdentifier>
      namespaceIdentifiers =
      generateNamespaceIdentifier(appId, env, clusterName, namespaceName);
  NamespaceDTO namespaceDTO = generateNamespaceDTO(appId, clusterName, namespaceName);

  when(namespaceAPI.loadNamespace(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(namespaceDTO);
  when(itemAPI.findItems(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(null);

  UserInfo userInfo = new UserInfo();
  userInfo.setUserId("test");
  when(userInfoHolder.getUser()).thenReturn(userInfo);

  List<ItemDiffs> itemDiffses = configService.compare(namespaceIdentifiers, sourceItems);

  assertEquals(1, itemDiffses.size());
  ItemDiffs itemDiffs = itemDiffses.get(0);
  ItemChangeSets changeSets = itemDiffs.getDiffs();
  assertEquals(0, changeSets.getUpdateItems().size());
  assertEquals(0, changeSets.getDeleteItems().size());

  List<ItemDTO> createItems = changeSets.getCreateItems();
  ItemDTO createItem = createItems.get(0);
  assertEquals(1, createItem.getLineNum());
  assertEquals("a", createItem.getKey());
  assertEquals("b", createItem.getValue());
  assertEquals("comment", createItem.getComment());
}
 
Example 18
Source File: XMLConfigAnnotationTest.java    From apollo with Apache License 2.0 4 votes vote down vote up
@ApolloConfigChangeListener(value = {ConfigConsts.NAMESPACE_APPLICATION, FX_APOLLO_NAMESPACE},
    interestedKeys = {"anotherKey"})
private void anotherOnChange(ConfigChangeEvent changeEvent) {

}
 
Example 19
Source File: JavaConfigAnnotationTest.java    From apollo with Apache License 2.0 4 votes vote down vote up
@ApolloConfigChangeListener(ConfigConsts.NAMESPACE_APPLICATION)
private void onChange2(ConfigChangeEvent changeEvent) {
  this.changeEvent2 = changeEvent;
}
 
Example 20
Source File: JavaConfigAnnotationTest.java    From apollo with Apache License 2.0 4 votes vote down vote up
@ApolloConfigChangeListener(value = {ConfigConsts.NAMESPACE_APPLICATION, FX_APOLLO_NAMESPACE},
    interestedKeys = {"anotherKey"})
private void anotherOnChange(ConfigChangeEvent changeEvent) {

}