use of com.cloud.api.response.StaticRouteResponse in project cosmic by MissionCriticalCloud.
the class CreateStaticRouteCmd method execute.
@Override
public void execute() throws ResourceUnavailableException {
boolean success = false;
StaticRoute route = null;
try {
CallContext.current().setEventDetails("Static route Id: " + getEntityId());
success = _vpcService.applyStaticRoute(getEntityId());
// State is different after the route is applied, so retrieve the object only here
route = _entityMgr.findById(StaticRoute.class, getEntityId());
StaticRouteResponse routeResponse = new StaticRouteResponse();
if (route != null) {
routeResponse = _responseGenerator.createStaticRouteResponse(route);
setResponseObject(routeResponse);
}
routeResponse.setResponseName(getCommandName());
} finally {
if (!success || route == null) {
_vpcService.revokeStaticRoute(getEntityId());
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create static route");
}
}
}
use of com.cloud.api.response.StaticRouteResponse in project cosmic by MissionCriticalCloud.
the class ListStaticRoutesCmd method execute.
@Override
public void execute() {
checkDeprecatedParameters();
final Pair<List<? extends StaticRoute>, Integer> result = _vpcService.listStaticRoutes(this);
final ListResponse<StaticRouteResponse> response = new ListResponse<>();
final List<StaticRouteResponse> routeResponses = new ArrayList<>();
result.first().forEach(route -> {
final StaticRouteResponse ruleData = _responseGenerator.createStaticRouteResponse(route);
routeResponses.add(ruleData);
});
response.setResponses(routeResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.api.response.StaticRouteResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createStaticRouteResponse.
@Override
public StaticRouteResponse createStaticRouteResponse(final StaticRoute result) {
final StaticRouteResponse response = new StaticRouteResponse();
response.setId(result.getUuid());
if (result.getVpcId() != null) {
final Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
if (vpc != null) {
response.setVpcId(vpc.getUuid());
}
}
response.setCidr(result.getCidr());
response.setGwIpAddress(result.getGwIpAddress());
StaticRoute.State state = result.getState();
if (state.equals(StaticRoute.State.Revoke)) {
state = StaticRoute.State.Deleting;
}
response.setState(state.toString());
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.StaticRoute, result.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("staticroute");
return response;
}
Aggregations