Search in sources :

Example 16 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class ServerDBSyncImpl method syncVirtualNetwork.

/*
     *  Virtual Network Synchronization methods
     */
@SuppressWarnings({ "unchecked" })
public boolean syncVirtualNetwork() throws Exception {
    final ApiConnector api = _manager.getApiConnector();
    try {
        List<TrafficType> types = new ArrayList<TrafficType>();
        types.add(TrafficType.Public);
        types.add(TrafficType.Guest);
        List<NetworkVO> dbNets = _manager.findManagedNetworks(types);
        List<VirtualNetwork> vList = (List<VirtualNetwork>) api.list(VirtualNetwork.class, null);
        List<VirtualNetwork> vncList = new ArrayList<VirtualNetwork>();
        for (VirtualNetwork vn : vList) {
            if (!_manager.isSystemDefaultNetwork(vn)) {
                vncList.add(vn);
            }
        }
        s_logger.debug("sync VN - DB size: " + dbNets.size() + " VNC Size: " + vncList.size());
        return _dbSync.syncGeneric(VirtualNetwork.class, dbNets, vncList);
    } catch (Exception ex) {
        s_logger.warn("sync virtual-networks", ex);
        throw ex;
    }
}
Also used : VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) NetworkVO(com.cloud.network.dao.NetworkVO) ApiConnector(net.juniper.contrail.api.ApiConnector) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) TrafficType(com.cloud.network.Networks.TrafficType)

Example 17 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class ServerDBSyncImpl method syncProject.

/*
     *  Project Synchronization methods
     */
@SuppressWarnings("unchecked")
public boolean syncProject() throws Exception {
    final ApiConnector api = _manager.getApiConnector();
    try {
        List<?> dbList = _projectDao.listAll();
        List<?> vncList = api.list(net.juniper.contrail.api.types.Project.class, null);
        return _dbSync.syncGeneric(net.juniper.contrail.api.types.Project.class, dbList, vncList);
    } catch (Exception ex) {
        s_logger.warn("syncProject", ex);
        throw ex;
    }
}
Also used : ApiConnector(net.juniper.contrail.api.ApiConnector) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException)

Example 18 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class ServerDBSyncImpl method deleteVirtualMachineInterfaces.

private void deleteVirtualMachineInterfaces(List<ObjectReference<ApiPropertyBase>> list, StringBuffer syncLogMesg) throws IOException {
    if (list == null) {
        return;
    }
    final ApiConnector api = _manager.getApiConnector();
    for (ObjectReference<ApiPropertyBase> vmiRef : list) {
        VirtualMachineInterface vmi = (VirtualMachineInterface) api.findById(VirtualMachineInterface.class, vmiRef.getUuid());
        deleteInstanceIps(vmi.getInstanceIpBackRefs(), syncLogMesg);
        deleteFloatingIps(vmi.getFloatingIpBackRefs(), syncLogMesg);
        api.delete(VirtualMachineInterface.class, vmiRef.getUuid());
        syncLogMesg.append("VNC vmi: " + vmi.getUuid() + " deleted\n");
    }
}
Also used : VirtualMachineInterface(net.juniper.contrail.api.types.VirtualMachineInterface) ApiConnector(net.juniper.contrail.api.ApiConnector) ApiPropertyBase(net.juniper.contrail.api.ApiPropertyBase)

Example 19 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class ServerDBSyncImpl method deleteProject.

public void deleteProject(net.juniper.contrail.api.types.Project vnc, StringBuffer syncLogMesg) throws IOException {
    final ApiConnector api = _manager.getApiConnector();
    api.read(vnc);
    syncLogMesg.append("Project# DB: none; VNC: " + vnc.getName() + "(" + vnc.getUuid() + "); action: delete\n");
    try {
        deleteChildren(vnc.getVirtualNetworks(), VirtualNetwork.class, syncLogMesg);
        deleteChildren(vnc.getSecurityGroups(), net.juniper.contrail.api.types.SecurityGroup.class, syncLogMesg);
        deleteChildren(vnc.getNetworkIpams(), net.juniper.contrail.api.types.NetworkIpam.class, syncLogMesg);
        deleteChildren(vnc.getNetworkPolicys(), net.juniper.contrail.api.types.NetworkPolicy.class, syncLogMesg);
    } catch (Exception ex) {
        s_logger.warn("deleteProject", ex);
    }
    api.delete(vnc);
    syncLogMesg.append("Project# VNC: " + vnc.getName() + " deleted\n");
}
Also used : ApiConnector(net.juniper.contrail.api.ApiConnector) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException)

Example 20 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class ServerDBSyncImpl method deleteChildren.

public <T extends ApiPropertyBase> void deleteChildren(List<ObjectReference<T>> childs, Class<?> childCls, StringBuffer syncLogMesg) throws Exception {
    final ApiConnector api = _manager.getApiConnector();
    if (childs == null) {
        syncLogMesg.append("no children of type: " + childCls.getName() + "\n");
        return;
    }
    syncLogMesg.append("delete children of type : " + DBSyncGeneric.getClassName(childCls) + "\n");
    String deleteChildMethod = "delete" + DBSyncGeneric.getClassName(childCls);
    Method method = null;
    Method[] methods = this.getClass().getMethods();
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().equalsIgnoreCase(deleteChildMethod)) {
            method = methods[i];
            break;
        }
    }
    int count = 0;
    for (ObjectReference<T> childRef : childs) {
        @SuppressWarnings("unchecked") ApiObjectBase child = api.findById((Class<? extends ApiObjectBase>) childCls, childRef.getUuid());
        if (method != null) {
            method.invoke(this, child, syncLogMesg);
        } else {
            deleteDefault(child, childCls, syncLogMesg);
        }
        count++;
    }
    syncLogMesg.append("deleted children count : " + count + "\n");
}
Also used : ApiObjectBase(net.juniper.contrail.api.ApiObjectBase) ApiConnector(net.juniper.contrail.api.ApiConnector) Method(java.lang.reflect.Method)

Aggregations

ApiConnector (net.juniper.contrail.api.ApiConnector)44 IOException (java.io.IOException)26 InternalErrorException (com.cloud.exception.InternalErrorException)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 ArrayList (java.util.ArrayList)8 NetworkVO (com.cloud.network.dao.NetworkVO)6 List (java.util.List)6 VMInstanceVO (com.cloud.vm.VMInstanceVO)5 ContrailManagerImpl (org.apache.cloudstack.network.contrail.management.ContrailManagerImpl)5 VlanDao (com.cloud.dc.dao.VlanDao)4 ApiConnectorMock (net.juniper.contrail.api.ApiConnectorMock)4 ObjectReference (net.juniper.contrail.api.ObjectReference)4 ServiceInstance (net.juniper.contrail.api.types.ServiceInstance)4 VirtualMachineInterface (net.juniper.contrail.api.types.VirtualMachineInterface)4 VirtualNetwork (net.juniper.contrail.api.types.VirtualNetwork)4 ContrailManager (org.apache.cloudstack.network.contrail.management.ContrailManager)4 Test (org.junit.Test)4 VlanVO (com.cloud.dc.VlanVO)3 NicVO (com.cloud.vm.NicVO)3 UserVmDao (com.cloud.vm.dao.UserVmDao)3