Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void execute() throws ResourceUnavailableException {
routeResponse.setResponseName(getCommandName());
} finally {
if (!success || route == null) {
_vpcService.revokeStaticRoute(getEntityId());
_entityMgr.remove(StaticRoute.class, getEntityId());
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create static route");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class ListStaticRoutesCmd extends BaseListTaggedResourcesCmd {
@Parameter(name = ApiConstants.GATEWAY_ID, type = CommandType.UUID, entityType = PrivateGatewayResponse.class, description = "list static routes by gateway id")
private Long gatewayId;

@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "list static routes by state")
private String state;

public Long getId() {
return id;
}
Expand All @@ -60,6 +63,10 @@ public Long getGatewayId() {
return gatewayId;
}

public String getState() {
return state;
}

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface StaticRouteDao extends GenericDao<StaticRouteVO, Long> {

List<StaticRouteVO> listByVpcId(long vpcId);

List<StaticRouteVO> listByGatewayId(long gatewayId);

long countRoutesByGateway(long gatewayId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected StaticRouteDaoImpl() {
RoutesByGatewayCount = createSearchBuilder(Long.class);
RoutesByGatewayCount.select(null, Func.COUNT, RoutesByGatewayCount.entity().getId());
RoutesByGatewayCount.and("gatewayId", RoutesByGatewayCount.entity().getVpcGatewayId(), Op.EQ);
RoutesByGatewayCount.and("state", RoutesByGatewayCount.entity().getState(), Op.EQ);
RoutesByGatewayCount.done();
}

Expand Down Expand Up @@ -91,10 +92,18 @@ public List<StaticRouteVO> listByVpcId(long vpcId) {
return listBy(sc);
}

@Override
public List<StaticRouteVO> listByGatewayId(long gatewayId) {
SearchCriteria<StaticRouteVO> sc = AllFieldsSearch.create();
sc.setParameters("gatewayId", gatewayId);
return listBy(sc);
}

@Override
public long countRoutesByGateway(long gatewayId) {
SearchCriteria<Long> sc = RoutesByGatewayCount.create();
sc.setParameters("gatewayId", gatewayId);
sc.setParameters("state", "Active");
return customSearch(sc, null).get(0);
}

Expand Down
18 changes: 17 additions & 1 deletion server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,10 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
}
}

// 2) Delete private gateway from the DB
// 2) Clean up any remaining routes
cleanUpRoutesByGatewayId(gatewayId);

// 3) Delete private gateway from the DB
return deletePrivateGatewayFromTheDB(gateway);

} finally {
Expand All @@ -2026,6 +2029,13 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
}
}

private void cleanUpRoutesByGatewayId(long gatewayId){
List<StaticRouteVO> routes = _staticRouteDao.listByGatewayId(gatewayId);
for (StaticRouteVO route: routes){
_staticRouteDao.remove(route.getId());
}
}

@DB
protected boolean deletePrivateGatewayFromTheDB(final PrivateGateway gateway) {
// check if there are ips allocted in the network
Expand Down Expand Up @@ -2318,6 +2328,7 @@ public Pair<List<? extends StaticRoute>, Integer> listStaticRoutes(final ListSta
final List<Long> permittedAccounts = new ArrayList<Long>();
final Map<String, String> tags = cmd.getTags();
final Long projectId = cmd.getProjectId();
final String state = cmd.getState();

final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive,
null);
Expand All @@ -2333,6 +2344,7 @@ public Pair<List<? extends StaticRoute>, Integer> listStaticRoutes(final ListSta
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ);
sb.and("vpcGatewayId", sb.entity().getVpcGatewayId(), SearchCriteria.Op.EQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);

if (tags != null && !tags.isEmpty()) {
final SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
Expand Down Expand Up @@ -2360,6 +2372,10 @@ public Pair<List<? extends StaticRoute>, Integer> listStaticRoutes(final ListSta
sc.addAnd("vpcGatewayId", Op.EQ, gatewayId);
}

if (state != null) {
sc.addAnd("state", Op.EQ, state);
}

if (tags != null && !tags.isEmpty()) {
int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.StaticRoute.toString());
Expand Down
3 changes: 2 additions & 1 deletion ui/scripts/vpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2652,7 +2652,8 @@
url: createURL('listStaticRoutes'),
data: {
gatewayid: args.context.vpcGateways[0].id,
listAll: true
listAll: true,
state: "Active"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Spaceman1984 can you send the related change to Primate as well cc @davidjumani

},
success: function(json) {
var items = json.liststaticroutesresponse.staticroute;
Expand Down