Search in sources :

Example 1 with ApiObjectBase

use of net.juniper.contrail.api.ApiObjectBase 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)

Example 2 with ApiObjectBase

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

the class PublicNetworkTest method testPublicNetwork.

@Test
public void testPublicNetwork() throws IOException {
    DataCenter zone = _server.getZone();
    List<NetworkVO> networks = _networksDao.listByZoneAndTrafficType(zone.getId(), TrafficType.Public);
    assertNotNull(networks);
    assertFalse(networks.isEmpty());
    UserVm vm1 = _server.createVM("test", networks.get(0));
    ArgumentCaptor<ApiObjectBase> createArg = ArgumentCaptor.forClass(ApiObjectBase.class);
    verify(_spy, times(4)).create(createArg.capture());
    List<ApiObjectBase> argumentList = createArg.getAllValues();
    ApiObjectBase vmObj = argumentList.get(0);
    assertEquals(VirtualNetwork.class, vmObj.getClass());
    assertEquals("__default_Public__", vmObj.getName());
    String vmiName = null;
    for (ApiObjectBase obj : argumentList) {
        if (obj.getClass() == VirtualMachineInterface.class) {
            vmiName = obj.getName();
        }
    }
    assertEquals("test-0", vmiName);
}
Also used : ApiObjectBase(net.juniper.contrail.api.ApiObjectBase) NetworkVO(com.cloud.network.dao.NetworkVO) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) Test(org.junit.Test)

Aggregations

ApiObjectBase (net.juniper.contrail.api.ApiObjectBase)2 DataCenter (com.cloud.dc.DataCenter)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 UserVm (com.cloud.uservm.UserVm)1 Method (java.lang.reflect.Method)1 ApiConnector (net.juniper.contrail.api.ApiConnector)1 Test (org.junit.Test)1