Search in sources :

Example 1 with NetScalerControlCenterVO

use of com.cloud.network.NetScalerControlCenterVO in project cloudstack by apache.

the class RegisterNetscalerControlCenterCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        NetScalerControlCenterVO nccVO = _netsclarLbService.registerNetscalerControlCenter(this);
        if (nccVO != null) {
            NetscalerControlCenterResponse response = _netsclarLbService.createNetscalerControlCenterResponse(nccVO);
            response.setObjectName("netscalerloadbalancer");
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add netscaler load balancer due to internal error.");
        }
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) NetscalerControlCenterResponse(com.cloud.api.response.NetscalerControlCenterResponse)

Example 2 with NetScalerControlCenterVO

use of com.cloud.network.NetScalerControlCenterVO in project cloudstack by apache.

the class NetscalerElement method deleteNetscalerControlCenter.

@DB
@Override
public boolean deleteNetscalerControlCenter(DeleteNetscalerControlCenterCmd cmd) throws CloudRuntimeException {
    NetScalerControlCenterVO result = _netscalerControlCenterDao.findByUuid(cmd.getId());
    if (result == null) {
        throw new CloudRuntimeException("External Netscaler Control Center Table does not contain record with this ID");
    } else {
        // ID list of Network Offering which are not removed and have service Package Uuid field not null.
        List<Long> servicePackageId_list = _networkOfferingDao.listNetworkOfferingID();
        if (servicePackageId_list.size() != 0) {
            // VO list of Networks  which are using Network Offering.
            List<NetworkVO> networkVO_list = _networkDao.listNetworkVO(servicePackageId_list);
            if (networkVO_list != null && networkVO_list.size() != 0) {
                throw new CloudRuntimeException("ServicePackages published by NetScalerControlCenter are being used by NetworkOfferings. Try deleting NetworkOffering with ServicePackages and then delete NetScalerControlCenter.");
            }
        }
    }
    try {
        _netscalerServicePackageDao.removeAll();
    } catch (CloudRuntimeException ce) {
        throw new CloudRuntimeException("Service Package is being used by Network Offering, Try deleting Network Offering and then delete Service Package.");
    }
    // delete Netscaler Control Center
    _netscalerControlCenterDao.remove(result.getId());
    // Removal of  NCC from Host Table
    List<HostVO> ncc_list = _hostDao.listAll();
    if (ncc_list == null) {
        throw new CloudRuntimeException("Could not find Netscaler Control Center in Database");
    }
    for (HostVO ncc : ncc_list) {
        if (ncc.getType().equals(Host.Type.NetScalerControlCenter)) {
            try {
                // put the host in maintenance state in order for it to be deleted
                ncc.setResourceState(ResourceState.Maintenance);
                _hostDao.update(ncc.getId(), ncc);
                _resourceMgr.deleteHost(ncc.getId(), false, false);
            } catch (Exception e) {
                s_logger.debug(e);
                return false;
            }
        }
    }
    return true;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) JSONException(org.json.JSONException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) DB(com.cloud.utils.db.DB)

Example 3 with NetScalerControlCenterVO

use of com.cloud.network.NetScalerControlCenterVO in project cloudstack by apache.

the class NetscalerElement method allocateNCCResourceForNetwork.

public HostVO allocateNCCResourceForNetwork(Network guestConfig) throws ConfigurationException {
    Map<String, String> _configs;
    List<NetScalerControlCenterVO> ncc = _netscalerControlCenterDao.listAll();
    HostVO hostVO = null;
    if (ncc.size() > 0) {
        NetScalerControlCenterVO nccVO = ncc.get(0);
        String ipAddress = nccVO.getNccip();
        Map hostDetails = new HashMap<String, String>();
        String hostName = "NetscalerControlCenter";
        hostDetails.put("name", hostName);
        hostDetails.put("guid", UUID.randomUUID().toString());
        hostDetails.put("zoneId", Long.toString(guestConfig.getDataCenterId()));
        hostDetails.put("ip", ipAddress);
        hostDetails.put("username", nccVO.getUsername());
        hostDetails.put("password", DBEncryptionUtil.decrypt(nccVO.getPassword()));
        hostDetails.put("deviceName", "netscaler control center");
        hostDetails.put("cmdTimeOut", Long.toString(NumbersUtil.parseInt(_configDao.getValue(Config.NCCCmdTimeOut.key()), 600000)));
        ServerResource resource = new NetScalerControlCenterResource();
        resource.configure(hostName, hostDetails);
        final Host host = _resourceMgr.addHost(guestConfig.getDataCenterId(), resource, Host.Type.NetScalerControlCenter, hostDetails);
        hostVO = _hostDao.findById(host.getId());
    }
    return hostVO;
}
Also used : HashMap(java.util.HashMap) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) ServerResource(com.cloud.resource.ServerResource) Host(com.cloud.host.Host) Map(java.util.Map) HashMap(java.util.HashMap) NetScalerControlCenterResource(com.cloud.network.resource.NetScalerControlCenterResource) HostVO(com.cloud.host.HostVO)

Example 4 with NetScalerControlCenterVO

use of com.cloud.network.NetScalerControlCenterVO in project cloudstack by apache.

the class NetscalerElement method registerNetscalerControlCenter.

@Override
@DB
public NetScalerControlCenterVO registerNetscalerControlCenter(RegisterNetscalerControlCenterCmd cmd) {
    if (_netscalerControlCenterDao.listAll() != null && _netscalerControlCenterDao.listAll().size() != 0) {
        throw new CloudRuntimeException("One Netscaler Control Center already exist in the DataBase. At a time only one Netscaler Control Center is allowed");
    }
    final RegisterNetscalerControlCenterCmd cmdinfo = cmd;
    String ipAddress = cmd.getIpaddress();
    Map hostDetails = new HashMap<String, String>();
    String hostName = "NetscalerControlCenter";
    hostDetails.put("name", hostName);
    hostDetails.put("guid", UUID.randomUUID().toString());
    List<DataCenterVO> dcVO = _dcDao.listEnabledZones();
    if (dcVO.size() == 0) {
        throw new CloudRuntimeException("There is no single enabled zone. Please add a zone, enable it and then add Netscaler ControlCenter");
    }
    hostDetails.put("zoneId", "1");
    hostDetails.put("ip", ipAddress);
    hostDetails.put("username", cmd.getUsername());
    hostDetails.put("password", cmd.getPassword());
    hostDetails.put("deviceName", "Netscaler ControlCenter");
    ServerResource resource = new NetScalerControlCenterResource();
    try {
        resource.configure(hostName, hostDetails);
        return Transaction.execute(new TransactionCallback<NetScalerControlCenterVO>() {

            @Override
            public NetScalerControlCenterVO doInTransaction(TransactionStatus status) {
                NetScalerControlCenterVO nccVO = new NetScalerControlCenterVO(cmdinfo.getUsername(), DBEncryptionUtil.encrypt(cmdinfo.getPassword()), cmdinfo.getIpaddress(), cmdinfo.getNumretries());
                _netscalerControlCenterDao.persist(nccVO);
                return nccVO;
            }
        });
    } catch (ConfigurationException e) {
        resource = null;
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : RegisterNetscalerControlCenterCmd(com.cloud.api.commands.RegisterNetscalerControlCenterCmd) DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Map(java.util.Map) HashMap(java.util.HashMap) NetScalerControlCenterResource(com.cloud.network.resource.NetScalerControlCenterResource) DB(com.cloud.utils.db.DB)

Example 5 with NetScalerControlCenterVO

use of com.cloud.network.NetScalerControlCenterVO in project cloudstack by apache.

the class ListNetscalerControlCenterCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<NetScalerControlCenterVO> lncCenters = _netsclarLbService.listNetscalerControlCenter(this);
        if (lncCenters != null) {
            ListResponse<NetscalerControlCenterResponse> response = new ListResponse<NetscalerControlCenterResponse>();
            List<NetscalerControlCenterResponse> lncCentersResponse = new ArrayList<NetscalerControlCenterResponse>();
            if (lncCenters != null && !lncCenters.isEmpty()) {
                for (NetScalerControlCenterVO lncCentersVO : lncCenters) {
                    NetscalerControlCenterResponse lncCentreResponse = _netsclarLbService.createNetscalerControlCenterResponse(lncCentersVO);
                    lncCentersResponse.add(lncCentreResponse);
                }
            }
            response.setResponses(lncCentersResponse);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list Net scalar Control Center due to some  internal error.");
        }
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) ArrayList(java.util.ArrayList) NetscalerControlCenterResponse(com.cloud.api.response.NetscalerControlCenterResponse)

Aggregations

NetScalerControlCenterVO (com.cloud.network.NetScalerControlCenterVO)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 NetscalerControlCenterResponse (com.cloud.api.response.NetscalerControlCenterResponse)2 HostVO (com.cloud.host.HostVO)2 NetScalerControlCenterResource (com.cloud.network.resource.NetScalerControlCenterResource)2 ServerResource (com.cloud.resource.ServerResource)2 DB (com.cloud.utils.db.DB)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfigurationException (javax.naming.ConfigurationException)2 RegisterNetscalerControlCenterCmd (com.cloud.api.commands.RegisterNetscalerControlCenterCmd)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 Host (com.cloud.host.Host)1