-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from yiming187/item_update
Add update API for item/release
- Loading branch information
Showing
9 changed files
with
194 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...dminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemSetController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ctrip.apollo.adminservice.controller; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.ctrip.apollo.biz.service.ItemSetService; | ||
import com.ctrip.apollo.core.dto.ItemChangeSets; | ||
|
||
@RestController | ||
public class ItemSetController { | ||
|
||
@Autowired | ||
private ItemSetService itemSetService; | ||
|
||
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset", method = RequestMethod.POST) | ||
public ResponseEntity<Void> create(@RequestBody ItemChangeSets changeSet) { | ||
itemSetService.updateSet(changeSet); | ||
return ResponseEntity.status(HttpStatus.OK).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemSetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ctrip.apollo.biz.service; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.ctrip.apollo.biz.entity.Item; | ||
import com.ctrip.apollo.biz.repository.ItemRepository; | ||
import com.ctrip.apollo.biz.utils.BeanUtils; | ||
import com.ctrip.apollo.core.dto.ItemChangeSets; | ||
import com.ctrip.apollo.core.dto.ItemDTO; | ||
|
||
@Service | ||
public class ItemSetService { | ||
|
||
@Autowired | ||
private ItemRepository itemRepository; | ||
|
||
public void updateSet(ItemChangeSets changeSet) { | ||
for (ItemDTO item : changeSet.getCreateItems()) { | ||
Item entity = BeanUtils.transfrom(Item.class, item); | ||
itemRepository.save(entity); | ||
} | ||
|
||
for (ItemDTO item : changeSet.getUpdateItems()) { | ||
Item entity = BeanUtils.transfrom(Item.class, item); | ||
Item managedItem = itemRepository.findOne(entity.getId()); | ||
BeanUtils.copyEntityProperties(entity, managedItem); | ||
itemRepository.save(managedItem); | ||
} | ||
|
||
for (ItemDTO item : changeSet.getDeletedItems()) { | ||
Item entity = BeanUtils.transfrom(Item.class, item); | ||
itemRepository.delete(entity.getId()); | ||
} | ||
} | ||
} |
46 changes: 44 additions & 2 deletions
46
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ReleaseService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,65 @@ | ||
package com.ctrip.apollo.biz.service; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.ctrip.apollo.biz.entity.Item; | ||
import com.ctrip.apollo.biz.entity.Namespace; | ||
import com.ctrip.apollo.biz.entity.Release; | ||
import com.ctrip.apollo.biz.repository.ItemRepository; | ||
import com.ctrip.apollo.biz.repository.NamespaceRepository; | ||
import com.ctrip.apollo.biz.repository.ReleaseRepository; | ||
import com.ctrip.apollo.core.exception.NotFoundException; | ||
import com.google.gson.Gson; | ||
|
||
/** | ||
* @author Jason Song(song_s@ctrip.com) | ||
*/ | ||
@Service | ||
public class ReleaseService { | ||
|
||
@Autowired | ||
private ReleaseRepository releaseRepository; | ||
|
||
|
||
@Autowired | ||
private NamespaceRepository namespaceRepository; | ||
|
||
@Autowired | ||
private ItemRepository itemRepository; | ||
|
||
private Gson gson = new Gson(); | ||
|
||
public Release findOne(long releaseId) { | ||
Release release = releaseRepository.findOne(releaseId); | ||
return release; | ||
} | ||
|
||
public Release buildRelease(String name, String comment, String appId, String clusterName, | ||
String namespaceName) { | ||
Namespace namespace = namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(appId, | ||
clusterName, namespaceName); | ||
if (namespace == null) { | ||
throw new NotFoundException(String.format("Could not find namespace for %s %s %s", appId, | ||
clusterName, namespaceName)); | ||
} | ||
List<Item> items = itemRepository.findByNamespaceId(namespace.getId()); | ||
Map<String, String> configurations = new HashMap<String, String>(); | ||
for (Item item : items) { | ||
configurations.put(item.getKey(), item.getValue()); | ||
} | ||
|
||
Release release = new Release(); | ||
release.setName(name); | ||
release.setComment(comment); | ||
release.setAppId(appId); | ||
release.setClusterName(clusterName); | ||
release.setNamespaceName(namespaceName); | ||
release.setConfigurations(gson.toJson(configurations)); | ||
return releaseRepository.save(release); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters