Skip to content

Commit

Permalink
Fixed the issue osc-core issue opensecuritycontroller#543
Browse files Browse the repository at this point in the history
  • Loading branch information
balmukundblr committed Dec 12, 2017
1 parent df0507e commit 7109846
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ public static synchronized Long generateUniqueTag(EntityManager em, VirtualSyste
}

public static boolean isProtectingWorkload(VirtualSystem vs) {
return !vs.getServiceFunctionChains().isEmpty() ||
CollectionUtils.emptyIfNull(vs.getDeploymentSpecs()).stream().anyMatch(ds -> DeploymentSpecEntityMgr.isProtectingWorkload(ds));
return CollectionUtils.emptyIfNull(vs.getDeploymentSpecs()).stream().anyMatch(ds -> DeploymentSpecEntityMgr.isProtectingWorkload(ds));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
*******************************************************************************/
package org.osc.core.broker.service.validator;

import java.util.List;
import java.util.stream.Collectors;

import javax.persistence.EntityManager;

import org.osc.core.broker.model.entities.appliance.DistributedAppliance;
import org.osc.core.broker.model.entities.appliance.VirtualSystem;
import org.osc.core.broker.model.entities.virtualization.SecurityGroup;
import org.osc.core.broker.model.entities.virtualization.ServiceFunctionChain;
import org.osc.core.broker.service.exceptions.VmidcBrokerValidationException;
import org.osc.core.broker.service.persistence.DistributedApplianceEntityMgr;
import org.osc.core.broker.service.persistence.SecurityGroupEntityMgr;
import org.osc.core.broker.service.request.BaseDeleteRequest;

public class DeleteDistributedApplianceRequestValidator implements RequestValidator<BaseDeleteRequest,DistributedAppliance> {
Expand Down Expand Up @@ -53,6 +60,10 @@ public DistributedAppliance validateAndLoad(BaseDeleteRequest request) throws Ex
da.getId()));
}

// DE5296->Error message to be more appropriate when deleting a DA without
// deleting the SFC
validateDAReferenceToSfcAndSecurityGroup(em, da);

if (!da.getMarkedForDeletion() && request.isForceDelete()) {
throw new VmidcBrokerValidationException(
"Distributed Appilance with ID "
Expand All @@ -62,4 +73,26 @@ public DistributedAppliance validateAndLoad(BaseDeleteRequest request) throws Ex

return da;
}

private void validateDAReferenceToSfcAndSecurityGroup(EntityManager em, DistributedAppliance da) throws Exception {
for (VirtualSystem vs : da.getVirtualSystems()) {
if (!vs.getServiceFunctionChains().isEmpty()) {
// DE5296-->Look if these SFCs are binded to any of the SG of same DA
for (ServiceFunctionChain sfc : vs.getServiceFunctionChains()) {
List<SecurityGroup> sgList = SecurityGroupEntityMgr.listSecurityGroupsBySfcId(em, sfc.getId());
String sgNames = sgList.stream().filter(sg -> !sg.getMarkedForDeletion()).map(sg -> sg.getName())
.collect(Collectors.joining(", "));
if (!sgNames.isEmpty()) {
throw new VmidcBrokerValidationException(String.format(
"Cannot delete deployment appliance with name '%s' which is currently referencing Service Function Chain '%s' and binded to a SecurityGroup(s) '%s'",
da.getName(), sfc.getName(), sgNames));
} else if (sgNames.isEmpty() && sfc != null) {
throw new VmidcBrokerValidationException(String.format(
"Cannot delete deployment appliance with name '%s' which is currently referencing Service Function Chain '%s'",
da.getName(), sfc.getName()));
}
}
}
}
}
}

0 comments on commit 7109846

Please sign in to comment.