Skip to content

Commit

Permalink
Merge branch 'master' into keepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam authored Dec 16, 2017
2 parents 8d31e51 + d0bbf0d commit b2f24cb
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@ The project is licensed under the [Apache 2 license](https://github.com/ctripcor
![现金巴士](https://github.com/ctripcorp/apollo/blob/master/doc/images/known-users/cash-bus.png)
![锤子科技](https://github.com/ctripcorp/apollo/blob/master/doc/images/known-users/smartisan.png)
![头等仓](https://github.com/ctripcorp/apollo/blob/master/doc/images/known-users/toodc.png)
![吉祥航空](https://github.com/ctripcorp/apollo/blob/master/doc/images/known-users/juneyaoair.png)
![263移动通信](https://github.com/ctripcorp/apollo/blob/master/doc/images/known-users/263mobile.png)
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,53 @@ public String toString() {
.add("ownerName", ownerName)
.add("ownerEmail", ownerEmail).toString();
}

public static class Builder {

public Builder() {
}

private App app = new App();

public Builder name(String name) {
app.setName(name);
return this;
}

public Builder appId(String appId) {
app.setAppId(appId);
return this;
}

public Builder orgId(String orgId) {
app.setOrgId(orgId);
return this;
}

public Builder orgName(String orgName) {
app.setOrgName(orgName);
return this;
}

public Builder ownerName(String ownerName) {
app.setOrgName(ownerName);
return this;
}

public Builder ownerEmail(String ownerEmail) {
app.setOwnerEmail(ownerEmail);
return this;
}

public App build() {
return app;
}

}

public static Builder builder() {
return new Builder();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ private App transformToApp(AppModel appModel) {
throw new BadRequestException(String.format("AppId格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
}

App app = new App();
app.setAppId(appId);
app.setName(appName);
app.setOwnerName(ownerName);
app.setOrgId(orgId);
app.setOrgName(orgName);

return app;
return App.builder()
.appId(appId)
.name(appName)
.ownerName(ownerName)
.orgId(orgId)
.orgName(orgName)
.build();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel;

@RestController
Expand All @@ -32,7 +34,7 @@ public class ClusterController {
public ClusterDTO createCluster(@PathVariable String appId, @PathVariable String env,
@RequestBody ClusterDTO cluster) {

checkModel(cluster != null);
checkModel(Objects.nonNull(cluster));
RequestPrecondition.checkArgumentsNotEmpty(cluster.getAppId(), cluster.getName());

if (!InputValidator.isValidClusterNamespace(cluster.getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ConsumerToken createConsumer(@RequestBody Consumer consumer,

Consumer createdConsumer = consumerService.createConsumer(consumer);

if (expires == null) {
if (Objects.isNull(expires)) {
expires = DEFAULT_EXPIRES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel;

Expand Down Expand Up @@ -128,7 +129,7 @@ public List<ItemDTO> findBranchItems(@PathVariable("appId") String appId, @PathV
@RequestMapping(value = "/namespaces/{namespaceName}/diff", method = RequestMethod.POST, consumes = {
"application/json"})
public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model) {
checkModel(model != null && !model.isInvalid());
checkModel(Objects.nonNull(model) && !model.isInvalid());

return configService.compare(model.getSyncToNamespaces(), model.getSyncItems());
}
Expand All @@ -138,14 +139,14 @@ public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model) {
"application/json"})
public ResponseEntity<Void> update(@PathVariable String appId, @PathVariable String namespaceName,
@RequestBody NamespaceSyncModel model) {
checkModel(model != null && !model.isInvalid());
checkModel(Objects.nonNull(model) && !model.isInvalid());

configService.syncItems(model.getSyncToNamespaces(), model.getSyncItems());
return ResponseEntity.status(HttpStatus.OK).build();
}

private boolean isValidItem(ItemDTO item) {
return item != null && !StringUtils.isContainEmpty(item.getKey());
return Objects.nonNull(item) && !StringUtils.isContainEmpty(item.getKey());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel;

Expand All @@ -41,7 +42,7 @@ public ReleaseDTO createRelease(@PathVariable String appId,
@PathVariable String env, @PathVariable String clusterName,
@PathVariable String namespaceName, @RequestBody NamespaceReleaseModel model) {

checkModel(model != null);
checkModel(Objects.nonNull(model));
model.setAppId(appId);
model.setEnv(env);
model.setClusterName(clusterName);
Expand Down Expand Up @@ -74,7 +75,7 @@ public ReleaseDTO createGrayRelease(@PathVariable String appId,
@PathVariable String namespaceName, @PathVariable String branchName,
@RequestBody NamespaceReleaseModel model) {

checkModel(model != null);
checkModel(Objects.nonNull(model));
model.setAppId(appId);
model.setEnv(env);
model.setClusterName(branchName);
Expand Down Expand Up @@ -142,7 +143,7 @@ public void rollback(@PathVariable String env,
@PathVariable long releaseId) {
releaseService.rollback(Env.valueOf(env), releaseId);
ReleaseDTO release = releaseService.findReleaseById(Env.valueOf(env), releaseId);
if (release == null) {
if (Objects.isNull(release)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel;

/**
Expand All @@ -31,14 +33,14 @@ public class ServerConfigController {
@RequestMapping(value = "/server/config", method = RequestMethod.POST)
public ServerConfig createOrUpdate(@RequestBody ServerConfig serverConfig) {

checkModel(serverConfig != null);
checkModel(Objects.nonNull(serverConfig));
RequestPrecondition.checkArgumentsNotEmpty(serverConfig.getKey(), serverConfig.getValue());

String modifiedBy = userInfoHolder.getUser().getUserId();

ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey());

if (storedConfig == null) {//create
if (Objects.isNull(storedConfig)) {//create
serverConfig.setDataChangeCreatedBy(modifiedBy);
serverConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(serverConfig);
Expand Down
Binary file added doc/images/known-users/263mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/known-users/juneyaoair.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b2f24cb

Please sign in to comment.