mirror of https://github.com/apache/cloudstack.git
InternalLbVm: support for start/stop Internal lb vm
This commit is contained in:
parent
ae69f0ae56
commit
4530cebf2b
|
|
@ -63,5 +63,7 @@ public interface VirtualNetworkApplianceService {
|
|||
VirtualRouter startRouter(long id) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException;
|
||||
|
||||
VirtualRouter destroyRouter(long routerId, Account caller, Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
VirtualRouter findRouter(long routerId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import javax.inject.Inject;
|
|||
import org.apache.cloudstack.affinity.AffinityGroupService;
|
||||
import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerService;
|
||||
import org.apache.cloudstack.network.lb.InternalLoadBalancerService;
|
||||
import org.apache.cloudstack.query.QueryService;
|
||||
import org.apache.cloudstack.usage.UsageService;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -140,7 +141,8 @@ public abstract class BaseCmd {
|
|||
@Inject public NetworkModel _ntwkModel;
|
||||
@Inject public ApplicationLoadBalancerService _appLbService;
|
||||
@Inject public AffinityGroupService _affinityGroupService;
|
||||
@Inject public InternalLoadBalancerElementService _internalLbSvs;
|
||||
@Inject public InternalLoadBalancerElementService _internalLbElementSvc;
|
||||
@Inject public InternalLoadBalancerService _internalLbSvc;
|
||||
|
||||
|
||||
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;
|
||||
|
|
|
|||
|
|
@ -29,8 +29,10 @@ import com.cloud.async.AsyncJob;
|
|||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
|
|
@ -100,7 +102,15 @@ public class StartRouterCmd extends BaseAsyncCmd {
|
|||
@Override
|
||||
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
UserContext.current().setEventDetails("Router Id: "+getId());
|
||||
VirtualRouter result = _routerService.startRouter(id);
|
||||
VirtualRouter result = null;
|
||||
VirtualRouter router = _routerService.findRouter(getId());
|
||||
if (router == null) {
|
||||
throw new InvalidParameterValueException("Can't find router by id");
|
||||
} else if (router.getRole() == Role.INTERNAL_LB_VM) {
|
||||
result = _internalLbSvc.startInternalLbVm(getId(), UserContext.current().getCaller(), UserContext.current().getCallerUserId());
|
||||
} else {
|
||||
result = _routerService.startRouter(getId());
|
||||
}
|
||||
if (result != null){
|
||||
DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(result);
|
||||
routerResponse.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -28,8 +28,10 @@ import org.apache.log4j.Logger;
|
|||
import com.cloud.async.AsyncJob;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
|
|
@ -103,7 +105,16 @@ public class StopRouterCmd extends BaseAsyncCmd {
|
|||
@Override
|
||||
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
UserContext.current().setEventDetails("Router Id: "+getId());
|
||||
VirtualRouter result = _routerService.stopRouter(getId(), isForced());
|
||||
VirtualRouter result = null;
|
||||
VirtualRouter router = _routerService.findRouter(getId());
|
||||
if (router == null) {
|
||||
throw new InvalidParameterValueException("Can't find router by id");
|
||||
} else if (router.getRole() == Role.INTERNAL_LB_VM) {
|
||||
result = _internalLbSvc.stopInternalLbVm(getId(), isForced(), UserContext.current().getCaller(), UserContext.current().getCallerUserId());
|
||||
} else {
|
||||
result = _routerService.stopRouter(getId(), isForced());
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.network.lb;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
public interface InternalLoadBalancerService {
|
||||
|
||||
VirtualRouter startInternalLbVm(long internalLbVmId, Account caller, long callerUserId)
|
||||
throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
VirtualRouter stopInternalLbVm(long vmId, boolean forced, Account caller, long callerUserId)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ import com.cloud.utils.component.Manager;
|
|||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.vm.VirtualMachineProfile.Param;
|
||||
|
||||
public interface InternalLoadBalancerManager extends Manager{
|
||||
public interface InternalLoadBalancerManager extends Manager, InternalLoadBalancerService{
|
||||
/**
|
||||
* Destroys Internal LB vm instance
|
||||
* @param vmId
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ import com.cloud.exception.ConcurrentOperationException;
|
|||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
|
|
@ -116,7 +117,7 @@ import com.cloud.vm.dao.DomainRouterDao;
|
|||
import com.cloud.vm.dao.NicDao;
|
||||
|
||||
@Component
|
||||
@Local(value = { InternalLoadBalancerManager.class})
|
||||
@Local(value = { InternalLoadBalancerManager.class, InternalLoadBalancerService.class})
|
||||
public class InternalLoadBalancerManagerImpl extends ManagerBase implements
|
||||
InternalLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
|
||||
private static final Logger s_logger = Logger
|
||||
|
|
@ -539,12 +540,18 @@ InternalLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
}
|
||||
|
||||
|
||||
protected VirtualRouter stopInternalLbVm(long vmId, boolean forced, Account caller, long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
@Override
|
||||
public VirtualRouter stopInternalLbVm(long vmId, boolean forced, Account caller, long callerUserId) throws ConcurrentOperationException,
|
||||
ResourceUnavailableException {
|
||||
DomainRouterVO internalLbVm = _routerDao.findById(vmId);
|
||||
if (internalLbVm == null) {
|
||||
return null;
|
||||
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
|
||||
throw new InvalidParameterValueException("Can't find internal lb vm by id");
|
||||
}
|
||||
|
||||
return stopInternalLbVm(internalLbVm, forced, caller, callerUserId);
|
||||
}
|
||||
|
||||
protected VirtualRouter stopInternalLbVm(DomainRouterVO internalLbVm, boolean forced, Account caller, long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
s_logger.debug("Stopping internal lb vm " + internalLbVm);
|
||||
try {
|
||||
if (_itMgr.advanceStop((DomainRouterVO) internalLbVm, forced, _accountMgr.getActiveUser(callerUserId), caller)) {
|
||||
|
|
@ -578,7 +585,7 @@ InternalLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
|
||||
for (DomainRouterVO internalLbVm : internalLbVms) {
|
||||
if (internalLbVm.getState() != VirtualMachine.State.Running) {
|
||||
internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
|
||||
internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
|
||||
}
|
||||
|
||||
if (internalLbVm != null) {
|
||||
|
|
@ -768,7 +775,7 @@ InternalLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
|
||||
if (startVm) {
|
||||
try {
|
||||
internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
|
||||
internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
|
||||
break;
|
||||
} catch (InsufficientCapacityException ex) {
|
||||
if (startRetry < 2 && iter.hasNext()) {
|
||||
|
|
@ -793,11 +800,11 @@ InternalLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
|
||||
|
||||
|
||||
protected DomainRouterVO startInternalLbVm(DomainRouterVO internalLbVm, User user, Account caller, long callerUserId, Map<Param, Object> params)
|
||||
protected DomainRouterVO startInternalLbVm(DomainRouterVO internalLbVm, Account caller, long callerUserId, Map<Param, Object> params)
|
||||
throws StorageUnavailableException, InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
s_logger.debug("Starting Internal LB VM " + internalLbVm);
|
||||
if (_itMgr.start(internalLbVm, params, user, caller, null) != null) {
|
||||
if (_itMgr.start(internalLbVm, params, _accountMgr.getUserIncludingRemoved(callerUserId), caller, null) != null) {
|
||||
if (internalLbVm.isStopPending()) {
|
||||
s_logger.info("Clear the stop pending flag of Internal LB VM " + internalLbVm.getHostName() + " after start router successfully!");
|
||||
internalLbVm.setStopPending(false);
|
||||
|
|
@ -886,4 +893,18 @@ InternalLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VirtualRouter startInternalLbVm(long internalLbVmId, Account caller, long callerUserId)
|
||||
throws StorageUnavailableException, InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
|
||||
DomainRouterVO internalLbVm = _routerDao.findById(internalLbVmId);
|
||||
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
|
||||
throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
|
||||
}
|
||||
|
||||
return startInternalLbVm(internalLbVm, caller, callerUserId, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1475,6 +1475,9 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
@Override
|
||||
public boolean revokeLoadBalancersForNetwork(long networkId, Scheme scheme) throws ResourceUnavailableException {
|
||||
List<LoadBalancerVO> lbs = _lbDao.listByNetworkIdAndScheme(networkId, scheme);
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Revoking " + lbs.size() + " " + scheme + " load balancing rules for network id=" + networkId);
|
||||
}
|
||||
if (lbs != null) {
|
||||
for(LoadBalancerVO lb : lbs) { // called during restart, not persisting state in db
|
||||
lb.setState(FirewallRule.State.Revoke);
|
||||
|
|
|
|||
|
|
@ -3742,4 +3742,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public VirtualRouter findRouter(long routerId) {
|
||||
return _routerDao.findById(routerId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -408,4 +408,10 @@ VpcVirtualNetworkApplianceService {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualRouter findRouter(long routerId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue