Skip to content

Commit

Permalink
Merge branch 'master' into osc_core_DA_SFC_Error_Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
balmukundblr authored Jan 12, 2018
2 parents 14d1494 + 238bf0f commit abfab86
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 52 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
<copy tofile="Build${fullVersion}/SampleMgrPlugin.bar">
<fileset dir="${basedir}/../security-mgr-sample-plugin/target/" includes="SampleMgrPlugin*.bar" />
</copy>
<copy tofile="Build${fullVersion}/PANMgrPlugin.bar">
<fileset dir="${basedir}/../osc-pan-plugin/target/" includes="PANMgrPlugin*.bar" />
<copy tofile="Build${fullVersion}/Panorama.bar">
<fileset dir="${basedir}/../osc-pan-plugin/target/" includes="Panorama*.bar" />
</copy>
<copy tofile="Build${fullVersion}/NscSdnControllerPlugin.bar">
<fileset dir="${basedir}/../sdn-controller-nsc-plugin/target/" includes="NscSdnControllerPlugin*.bar" />
Expand Down
4 changes: 2 additions & 2 deletions osc-export/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@
dir="${basedir}/../../security-mgr-sample-plugin/target/"
includes="SampleMgrPlugin*.bar" />
</copy>
<copy tofile="${basedir}/data/plugins/PANMgrPlugin.bar">
<copy tofile="${basedir}/data/plugins/Panorama.bar">
<fileset
dir="${basedir}/../../osc-pan-plugin/target/"
includes="PANMgrPlugin*.bar" />
includes="Panorama*.bar" />
</copy>
<copy tofile="${basedir}/data/plugins/NscSdnControllerPlugin.bar">
<fileset dir="${basedir}/../../sdn-controller-nsc-plugin/target/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
Expand Down Expand Up @@ -122,19 +123,20 @@ public BaseJobResponse exec(BindSecurityGroupRequest request, EntityManager em)
throw new VmidcBrokerValidationException(
"Security group interface cannot have more than one policy for security manager not supporting multiple policy binding");
}
if (!isPolicyMappingSupported && !serviceToBindTo.getPolicyIds().isEmpty()) {
throw new VmidcBrokerValidationException(
"Security manager not supporting policy mapping cannot have one or more policies");
}
if (isPolicyMappingSupported && serviceToBindTo.getPolicyIds().isEmpty()) {
throw new VmidcBrokerValidationException(
"Service to bind: " + serviceToBindTo + " must have a policy id.");
}

Set<Policy> policies = null;
policies = PolicyEntityMgr.findPoliciesById(em, serviceToBindTo.getPolicyIds(),
vs.getDistributedAppliance().getApplianceManagerConnector());
Set<Long> policyIds = serviceToBindTo.getPolicyIds() != null ? serviceToBindTo.getPolicyIds() : new HashSet<>();
if (!isPolicyMappingSupported && !policyIds.isEmpty()) {
throw new VmidcBrokerValidationException(
"Security manager not supporting policy mapping cannot have one or more policies");
}
if (isPolicyMappingSupported && policyIds.isEmpty()) {
throw new VmidcBrokerValidationException(
"Service to bind: " + serviceToBindTo + " must have a policy id.");
}

Set<Policy> policies = null;
policies = PolicyEntityMgr.findPoliciesById(em, policyIds,
vs.getDistributedAppliance().getApplianceManagerConnector());
if (this.apiFactoryService.supportsFailurePolicy(this.securityGroup)) {
// If failure policy is supported, failure policy is a required field
if (serviceToBindTo.getFailurePolicyType() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*******************************************************************************/
package org.osc.core.broker.service.tasks.conformance.openstack.securitygroup;

import static java.util.stream.Collectors.toSet;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.EntityManager;
Expand All @@ -33,9 +36,9 @@
import org.osc.core.broker.model.entities.virtualization.openstack.VMPort;
import org.osc.core.broker.service.persistence.OSCEntityManager;
import org.osc.core.broker.service.tasks.TransactionalTask;
import org.slf4j.LoggerFactory;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(service=SecurityGroupMemberDeleteTask.class)
public class SecurityGroupMemberDeleteTask extends TransactionalTask {
Expand All @@ -60,21 +63,14 @@ public void executeTransaction(EntityManager em) throws Exception {
if (this.sgm.getType() == SecurityGroupMemberType.VM) {
VM vm = this.sgm.getVm();

if (vm.getSecurityGroupMembers().size() == 1) {
vm.getSecurityGroupMembers().remove(this.sgm);
if (vm.getSecurityGroupMembers().size() == 0) {
// VM has reference only to this SGM. Delete the vm too.
this.log.info("No other references to VM found. Deleting VM " + vm.getName());
int portsDeleted = 0;
int totalVmPorts = vm.getPorts().size();
for (VMPort vmport : vm.getPorts()) {
if (vmport.getNetwork() == null) {
OSCEntityManager.delete(em, vmport, this.txBroadcastUtil);
portsDeleted++;
}
}
if (portsDeleted == totalVmPorts) {
// Only if all ports were deleted, delete the VM.
OSCEntityManager.delete(em, vm, this.txBroadcastUtil);
}
Set<VMPort> portsToRemove = vm.getPorts().stream().filter(p -> p.getNetwork() == null).collect(toSet());

// If portsToRemove equals all ports, VM itself is deleted.
deleteFromDB(em, portsToRemove);
} else {
vm.getSecurityGroupMembers().remove(this.sgm);
}
Expand Down Expand Up @@ -109,17 +105,7 @@ public void executeTransaction(EntityManager em) throws Exception {
if (network.getSecurityGroupMembers().size() == 1) {
// Network has reference only to this SGM. Delete the network too.
this.log.info("No other references to Network found. Deleting Network " + network.getName());
for (VMPort vmPort : network.getPorts()) {
// If the VM was created on behalf of this port, delete it.
VM vm = vmPort.getVm();
OSCEntityManager.delete(em, vmPort, this.txBroadcastUtil);
if (vm != null) {
vm.removePort(vmPort);
if (vm.getSecurityGroupMembers().size() == 0 && vm.getPorts().size() <= 0) {
OSCEntityManager.delete(em, vm, this.txBroadcastUtil);
}
}
}
deleteFromDB(em, network.getPorts());
OSCEntityManager.delete(em, network, this.txBroadcastUtil);
}
this.log.info("Deleting Security Group member from " + this.sgm.getSecurityGroup().getName());
Expand All @@ -130,17 +116,7 @@ public void executeTransaction(EntityManager em) throws Exception {
if (subnet.getSecurityGroupMembers().size() == 1) {
// Subnet has reference only to this SGM. Delete the subnet too.
this.log.info("No other references to Subnet found. Deleting Subnet " + subnet.getName());
for (VMPort vmPort : subnet.getPorts()) {
// If the VM was created on behalf of this port, delete it.
VM vm = vmPort.getVm();
OSCEntityManager.delete(em, vmPort, this.txBroadcastUtil);
if (vm != null) {
vm.removePort(vmPort);
if (vm.getSecurityGroupMembers().size() == 0 && vm.getPorts().size() <= 0) {
OSCEntityManager.delete(em, vm, this.txBroadcastUtil);
}
}
}
deleteFromDB(em, subnet.getPorts());
OSCEntityManager.delete(em, subnet, this.txBroadcastUtil);
}
this.log.info("Deleting Security Group member from " + this.sgm.getSecurityGroup().getName());
Expand All @@ -160,4 +136,41 @@ public Set<LockObjectReference> getObjects() {
return LockObjectReference.getObjectReferences(this.sgm.getSecurityGroup());
}

private void deleteFromDB(EntityManager em, Set<VMPort> ports) {
Set<VM> vmsToRemove = new HashSet<>();

// guard against ConcurrentModificationException;
Set<VMPort> portsClone = new HashSet<>(ports);
for (VMPort vmPort : portsClone) {
VM vm = vmPort.getVm();
if (vm != null) {
vm.removePort(vmPort);
vmPort.setVm(null);
}

Network network = vmPort.getNetwork();
if (network != null) {
network.removePort(vmPort);
}

for (DistributedApplianceInstance dai : vmPort.getDais()) {
dai.removeProtectedPort(vmPort);
vmPort.removeDai(dai);
}

this.log.info("Removing port " + vmPort);
OSCEntityManager.delete(em, vmPort, this.txBroadcastUtil);

if (vm != null) {
if (vm.getSecurityGroupMembers().size() == 0 && vm.getPorts().size() <= 0) {
vmsToRemove.add(vm);
}
}
}

for (VM vm : vmsToRemove) {
this.log.info("Removing vm " + vm);
OSCEntityManager.delete(em, vm, this.txBroadcastUtil);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void buildTaskGraph(EntityManager em, boolean isDeleteTg, String domainI
// are already deleted and this essentially a no op. The tasks SecurityGroupMemberVmCheckTask etc
// need to make sure hooks are removed in case of delete tg.
boolean shouldRemoveHooks = !this.apiFactoryService.supportsPortGroup(this.sg)
|| !this.apiFactoryService.supportsNeutronSFC(this.sg);
&& !this.apiFactoryService.supportsNeutronSFC(this.sg);
if (shouldRemoveHooks) {
tasksToSucceedToDeleteSGI.addAll(addSGMemberRemoveHooksTask(em, sgi));
}
Expand Down

0 comments on commit abfab86

Please sign in to comment.