Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
lepdou committed Sep 22, 2021
2 parents ea7e4f3 + 2fb3479 commit f709e33
Show file tree
Hide file tree
Showing 62 changed files with 2,557 additions and 346 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
text=auto
text=auto
*.sh text eol=lf
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Apollo 1.10.0
* [remove ctrip profile](https://github.com/ctripcorp/apollo/pull/3920)
* [Remove spring dependencies from internal code](https://github.com/apolloconfig/apollo/pull/3937)
* [Fix issue: ingress syntax](https://github.com/apolloconfig/apollo/pull/3933)
* [refactor: let open api more easier to use and development](https://github.com/apolloconfig/apollo/pull/3943)
* [feat(scripts): use bash to call openapi](https://github.com/apolloconfig/apollo/pull/3980)
* [Support search by item](https://github.com/apolloconfig/apollo/pull/3977)
* [Support export/import configs](https://github.com/apolloconfig/apollo/pull/3947)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.dto.PageDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -87,6 +91,18 @@ public NamespaceDTO get(@PathVariable("namespaceId") Long namespaceId) {
return BeanUtils.transform(NamespaceDTO.class, namespace);
}

/**
* the returned content's size is not fixed. so please carefully used.
*/
@GetMapping("/namespaces/find-by-item")
public PageDTO<NamespaceDTO> findByItem(@RequestParam String itemKey, Pageable pageable) {
Page<Namespace> namespacePage = namespaceService.findByItem(itemKey, pageable);

List<NamespaceDTO> namespaceDTOS = BeanUtils.batchTransform(NamespaceDTO.class, namespacePage.getContent());

return new PageDTO<>(namespaceDTOS, pageable, namespacePage.getTotalElements());
}

@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}")
public NamespaceDTO get(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.ctrip.framework.apollo.biz.entity.Item;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
Expand All @@ -35,6 +37,8 @@ public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {

List<Item> findByNamespaceIdAndDataChangeLastModifiedTimeGreaterThan(Long namespaceId, Date date);

Page<Item> findByKey(String key, Pageable pageable);

Item findFirst1ByNamespaceIdOrderByLineNumDesc(Long namespaceId);

@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;
import java.util.Set;

public interface NamespaceRepository extends PagingAndSortingRepository<Namespace, Long> {

Expand All @@ -39,6 +40,8 @@ public interface NamespaceRepository extends PagingAndSortingRepository<Namespac

List<Namespace> findByNamespaceName(String namespaceName, Pageable page);

List<Namespace> findByIdIn(Set<Long> namespaceIds);

int countByNamespaceNameAndAppIdNot(String namespaceName, String appId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -138,6 +140,10 @@ public List<Item> findItemsModifiedAfterDate(long namespaceId, Date date) {
return itemRepository.findByNamespaceIdAndDataChangeLastModifiedTimeGreaterThan(namespaceId, date);
}

public Page<Item> findItemsByKey(String key, Pageable pageable) {
return itemRepository.findByKey(key, pageable);
}

@Transactional
public Item save(Item entity) {
checkItemKeyLength(entity.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -104,6 +106,21 @@ public Namespace findOne(String appId, String clusterName, String namespaceName)
namespaceName);
}

/**
* the returned content's size is not fixed. so please carefully used.
*/
public Page<Namespace> findByItem(String itemKey, Pageable pageable) {
Page<Item> items = itemService.findItemsByKey(itemKey, pageable);

if (!items.hasContent()) {
return Page.empty();
}

Set<Long> namespaceIds = BeanUtils.toPropertySet("namespaceId", items.getContent());

return new PageImpl<>(namespaceRepository.findByIdIn(namespaceIds));
}

public Namespace findPublicNamespaceForAssociatedNamespace(String clusterName, String namespaceName) {
AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName);
if (appNamespace == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,44 +344,4 @@ public interface StringFormatter<T> {
String format(T obj);
}

public static <T> String join(Collection<T> collection, String separator) {
return join(collection, separator, new StringFormatter<T>() {
@Override
public String format(T obj) {
return obj.toString();
}
});
}

public static <T> String join(Collection<T> collection, String separator,
StringFormatter<T> formatter) {
Iterator<T> iterator = collection.iterator();
// handle null, zero and one elements before building a buffer
if (iterator == null) {
return null;
}
if (!iterator.hasNext()) {
return EMPTY;
}
T first = iterator.next();
if (!iterator.hasNext()) {
return first == null ? "" : formatter.format(first);
}

// two or more elements
StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
if (first != null) {
buf.append(formatter.format(first));
}

while (iterator.hasNext()) {
buf.append(separator);
T obj = iterator.next();
if (obj != null) {
buf.append(formatter.format(obj));
}
}

return buf.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.ctrip.framework.apollo.core.utils;

import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -68,19 +67,6 @@ public void testIsNumeric() {
Assert.assertTrue(StringUtils.isNumeric("1"));
}

@Test
public void testJoin() {
Assert.assertEquals("", StringUtils.join(new ArrayList(), "1a 2b 3c"));

ArrayList collection = new ArrayList();
collection.add(null);
Assert.assertEquals("", StringUtils.join(collection, "1a 2b 3c"));

collection = new ArrayList();
collection.add(-2_147_483_648);
Assert.assertEquals("-2147483648", StringUtils.join(collection, "1a 2b 3c"));
}

@Test
public void testStartsWithIgnoreCase() {
Assert.assertFalse(StringUtils.startsWithIgnoreCase("A1B2C3", "BAZ"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenEnvClusterDTO;
import java.util.List;

/**
* @author wxq
*/
public interface AppOpenApiService {

List<OpenEnvClusterDTO> getEnvClusterInfo(String appId);

List<OpenAppDTO> getAllApps();

List<OpenAppDTO> getAppsInfo(List<String> appIds);

List<OpenAppDTO> getAuthorizedApps();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO;

/**
* @author wxq
*/
public interface ClusterOpenApiService {

OpenClusterDTO getCluster(String appId, String env, String clusterName);

OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;

/**
* @author wxq
*/
public interface ItemOpenApiService {

OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName,
String key);

OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName,
OpenItemDTO itemDTO);

void updateItem(String appId, String env, String clusterName, String namespaceName,
OpenItemDTO itemDTO);

void createOrUpdateItem(String appId, String env, String clusterName, String namespaceName,
OpenItemDTO itemDTO);

void removeItem(String appId, String env, String clusterName, String namespaceName, String key,
String operator);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO;
import java.util.List;

/**
* @author wxq
*/
public interface NamespaceOpenApiService {

OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName);

List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName);

OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDTO);

OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName,
String namespaceName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.NamespaceReleaseDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenReleaseDTO;

/**
* @author wxq
*/
public interface ReleaseOpenApiService {

OpenReleaseDTO publishNamespace(String appId, String env, String clusterName,
String namespaceName,
NamespaceReleaseDTO releaseDTO);

OpenReleaseDTO getLatestActiveRelease(String appId, String env, String clusterName,
String namespaceName);

void rollbackRelease(String env, long releaseId, String operator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
* Get all App information
*/
public List<OpenAppDTO> getAllApps() {
return appService.getAppsInfo(null);
return appService.getAllApps();
}

/**
Expand Down
Loading

0 comments on commit f709e33

Please sign in to comment.