com.vmware.vim25.RuntimeFaultFaultMsg Java Examples

The following examples show how to use com.vmware.vim25.RuntimeFaultFaultMsg. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicConnection.java    From cs-actions with Apache License 2.0 7 votes vote down vote up
@SuppressWarnings("rawtypes")
private void makeConnection(String url, String username, String password, boolean trustEveryone)
        throws RuntimeFaultFaultMsg,
        InvalidLocaleFaultMsg,
        InvalidLoginFaultMsg,
        KeyManagementException,
        NoSuchAlgorithmException {

    vimService = new VimService();
    vimPort = vimService.getVimPort();

    populateContextMap(url, username, password);

    if (Boolean.TRUE.equals(trustEveryone)) {
        DisableSecurity.trustEveryone();
    }

    serviceContent = vimPort.retrieveServiceContent(this.getServiceInstanceReference());
    userSession = vimPort.login(serviceContent.getSessionManager(), username, password, null);
}
 
Example #2
Source File: WaitForValues.java    From vsphere-automation-sdk-java with MIT License 6 votes vote down vote up
/**
 * This method returns a boolean value specifying whether the Task is
 * succeeded or failed.
 *
 * @param task
 *            ManagedObjectReference representing the Task.
 * @return boolean value representing the Task result.
 * @throws InvalidCollectorVersionFaultMsg
 *
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
public boolean getTaskResultAfterDone(ManagedObjectReference task)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg,
        InvalidCollectorVersionFaultMsg {

    boolean retVal = false;

    // info has a property - state for state of the task
    Object[] result = wait(task,
            new String[] { "info.state", "info.error" },
            new String[] { "state" }, new Object[][] { new Object[] {
                TaskInfoState.SUCCESS, TaskInfoState.ERROR } });

    if (result[0].equals(TaskInfoState.SUCCESS)) {
        retVal = true;
    }
    if (result[1] instanceof LocalizedMethodFault) {
        throw new RuntimeException(
                ((LocalizedMethodFault) result[1]).getLocalizedMessage());
    }
    return retVal;
}
 
Example #3
Source File: VmUtils.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
public ManagedObjectReference getMorHost(String hostname, ConnectionResources connectionResources,
                                         ManagedObjectReference vmMor) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference host = null;
    if (isNotBlank(hostname)) {
        host = getManagedObjectReference(hostname, connectionResources,
                ManagedObjectType.HOST_SYSTEM.getValue(), ErrorMessages.HOST_NOT_FOUND);
    } else if (StringUtils.isBlank(hostname) && vmMor != null) {
        ObjectContent[] objectContents = GetObjectProperties.getObjectProperties(connectionResources, vmMor,
                new String[]{ManagedObjectType.SUMMARY.getValue()});

        for (ObjectContent objectItem : objectContents) {
            List<DynamicProperty> vmProperties = objectItem.getPropSet();
            for (DynamicProperty propertyItem : vmProperties) {
                VirtualMachineSummary virtualMachineSummary = (VirtualMachineSummary) propertyItem.getVal();
                host = virtualMachineSummary.getRuntime().getHost();
                break;
            }
            break;
        }
    } else {
        host = connectionResources.getHostMor();
    }
    return host;
}
 
Example #4
Source File: VmUtils.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
public ManagedObjectReference getMorResourcePool(String resourcePoolName, ConnectionResources connectionResources)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference resourcePool;
    if (isNotBlank(resourcePoolName)) {
        resourcePool = getManagedObjectReference(resourcePoolName, connectionResources,
                ManagedObjectType.RESOURCE_POOL.getValue(), ErrorMessages.RESOURCE_POOL_NOT_FOUND);
    } else {
        resourcePool = connectionResources.getResourcePoolMor();
        if (resourcePool == null) {
            ManagedObjectReference reference = connectionResources.getMorRootFolder();
            resourcePool = new MorObjectHandler().getSpecificMor(connectionResources, reference,
                    ManagedObjectType.RESOURCE_POOL.getValue(), ManagedObjectType.RESOURCES.getValue());
        }
    }
    return resourcePool;
}
 
Example #5
Source File: ClusterComputeResourceServiceTest.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
@Test
public void createAffinityRuleVmGroupNotFoundException() throws Exception {
    VmInputs vmInputs = getVmInputs();
    doReturn(clusterConfigInfoExMock).when(clusterComputeResourceServiceSpy, GET_CLUSTER_CONFIGURATION,
            any(ConnectionResources.class), any(ManagedObjectReference.class), any(String.class));
    doReturn(false).when(clusterComputeResourceServiceSpy, RULE_EXISTS,
            any(ClusterConfigInfoEx.class), any(String.class));
    whenNew(ClusterVmHostRuleInfo.class).withNoArguments().thenReturn(clusterVmHostRuleInfoMock);
    doReturn(clusterVmHostRuleInfoMock).when(clusterComputeResourceServiceSpy, ADD_AFFINE_GROUP_TO_RULE,
            any(ClusterVmHostRuleInfo.class), any(ClusterConfigInfoEx.class), any(String.class));
    doThrow(new RuntimeFaultFaultMsg(VM_GROUP_DOES_NOT_EXIST, new RuntimeFault()))
            .when(clusterComputeResourceServiceSpy, EXISTS_GROUP,
                    any(ClusterConfigInfoEx.class), any(String.class), any(Class.class));
    thrownException.expectMessage(VM_GROUP_DOES_NOT_EXIST);

    clusterComputeResourceServiceSpy.createAffinityRule(httpInputsMock, vmInputs, "affineHostGroupName", "");
}
 
Example #6
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
/**
 * Method to retrieve properties of a {@link ManagedObjectReference}
 *
 * @param entityMor {@link ManagedObjectReference} of the entity
 * @param props     Array of properties to be looked up
 * @return Map of the property name and its corresponding value
 * @throws InvalidPropertyFaultMsg If a property does not exist
 * @throws RuntimeFaultFaultMsg
 */
public Map<String, Object> entityProps(ManagedObjectReference entityMor, String[] props)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    final HashMap<String, Object> retVal = new HashMap<>();
    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    PropertyFilterSpec[] propertyFilterSpecs = {new PropertyFilterSpecBuilder().propSet(
            // Create Property Spec
            new PropertySpecBuilder().all(false).type(entityMor.getType()).pathSet(props))
            .objectSet(
            // Now create Object Spec
            new ObjectSpecBuilder().obj(entityMor))};

    List<ObjectContent> objCont = vimPort.retrievePropertiesEx(serviceContent.getPropertyCollector(),
            Arrays.asList(propertyFilterSpecs), new RetrieveOptions()).getObjects();

    if (objCont != null) {
        for (ObjectContent oc : objCont) {
            List<DynamicProperty> dps = oc.getPropSet();
            for (DynamicProperty dp : dps) {
                retVal.put(dp.getName(), dp.getVal());
            }
        }
    }

    return retVal;
}
 
Example #7
Source File: ManagedObjectAccessor.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve contents for a single object based on the property collector
 * registered with the service.
 *
 * @param collector
 *            Property collector registered with service
 * @param mobj
 *            Managed Object Reference to get contents for
 * @param properties
 *            names of properties of object to retrieve
 *
 * @return retrieved object contents
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
private ObjectContent[] getObjectProperties(ManagedObjectReference mobj,
        String[] properties)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    if (mobj == null) {
        return null;
    }

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getPropSet().add(new PropertySpec());
    if ((properties == null || properties.length == 0)) {
        spec.getPropSet().get(0).setAll(Boolean.TRUE);
    } else {
        spec.getPropSet().get(0).setAll(Boolean.FALSE);
    }
    spec.getPropSet().get(0).setType(mobj.getType());
    spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties));
    spec.getObjectSet().add(new ObjectSpec());
    spec.getObjectSet().get(0).setObj(mobj);
    spec.getObjectSet().get(0).setSkip(Boolean.FALSE);
    List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
    listpfs.add(spec);
    List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);
    return listobjcont.toArray(new ObjectContent[listobjcont.size()]);
}
 
Example #8
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
private PropertyFilterSpec[] propertyFilterSpecs(ManagedObjectReference container,
                                                 String morefType,
                                                 String... morefProperties
) throws RuntimeFaultFaultMsg {
    ManagedObjectReference viewManager = serviceContent.getViewManager();
    ManagedObjectReference containerView = vimPort.createContainerView(viewManager, container,
            Arrays.asList(morefType), true);

    return new PropertyFilterSpec[]{
            new PropertyFilterSpecBuilder().propSet(new PropertySpecBuilder().all(false)
                    .type(morefType).pathSet(morefProperties)).objectSet(new ObjectSpecBuilder()
                    .obj(containerView).skip(true).selectSet(new TraversalSpecBuilder()
                            .name(ManagedObjectType.VIEW.getValue())
                            .path(ManagedObjectType.VIEW.getValue())
                            .skip(false)
                            .type(ManagedObjectType.CONTAINER_VIEW.getValue())))};
}
 
Example #9
Source File: ClusterComputeResourceServiceTest.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@Test
public void createHostGroupThrowsException() throws Exception {
    hostGroupMockInitializationOnExceptionThrown();
    VmInputs vmInputs = getVmInputs();
    List<String> hostList = getList();
    when(vimPortMock.reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class)))
            .thenThrow(new RuntimeFaultFaultMsg(CLUSTER_CONFIGURATION_FAILED, new RuntimeFault()));
    thrownException.expectMessage(CLUSTER_CONFIGURATION_FAILED);

    clusterComputeResourceService.createHostGroup(httpInputsMock, vmInputs, hostList);
}
 
Example #10
Source File: ClusterComputeResourceServiceTest.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@Test
public void listVmGroupsThrowsException() throws Exception {
    List<ClusterGroupInfo> clusterGroupInfoList = new ArrayList<>();
    ClusterConfigInfoEx clusterConfigInfoEx = new ClusterConfigInfoEx();
    clusterConfigInfoEx.getGroup().addAll(clusterGroupInfoList);
    doThrow(new RuntimeFaultFaultMsg(String.format(ErrorMessages.ANOTHER_FAILURE_MSG, "Cluster1"), new RuntimeFault()))
            .when(clusterComputeResourceServiceSpy, GET_CLUSTER_CONFIGURATION,
                    any(ConnectionResources.class), any(ManagedObjectReference.class), any(String.class));
    thrownException.expectMessage(String.format(ErrorMessages.ANOTHER_FAILURE_MSG, "Cluster1"));

    clusterComputeResourceServiceSpy.listGroups(httpInputsMock, "Cluster1", "", ClusterVmGroup.class);
}
 
Example #11
Source File: ClusterComputeResourceServiceTest.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteClusterRuleThrowsException() throws Exception {
    VmInputs vmInputs = getVmInputs();
    doReturn(clusterConfigInfoExSpy).when(clusterComputeResourceServiceSpy, GET_CLUSTER_CONFIGURATION,
            any(ConnectionResources.class), any(ManagedObjectReference.class), any(String.class));
    doReturn(clusterRuleInfoListMock).when(clusterConfigInfoExSpy, GET_RULE);
    doThrow(new RuntimeFaultFaultMsg(String.format(CLUSTER_RULE_COULD_NOT_BE_FOUND, vmInputs.getRuleName()), new RuntimeFault()))
            .when(clusterComputeResourceServiceSpy, GET_CLUSTER_RULE_INFO,
                    any(List.class), any(String.class));

    thrownException.expectMessage(String.format(CLUSTER_RULE_COULD_NOT_BE_FOUND, vmInputs.getRuleName()));
    clusterComputeResourceServiceSpy.deleteClusterRule(httpInputsMock, vmInputs);
}
 
Example #12
Source File: ClusterComputeResourceServiceTest.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void commonVerifications() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    verify(connectionResourcesMock, times(1)).getConnection();
    verify(connectionResourcesMock, times(1)).getVimPortType();
    verify(morObjectHandlerMock, times(1)).getSpecificMor(any(ConnectionResources.class), any(ManagedObjectReference.class), any(String.class), any(String.class));
    verify(vimPortMock, times(1)).reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class));
    verify(taskMock, times(1)).getValue();
    verify(connectionMock, times(1)).disconnect();
}
 
Example #13
Source File: ManagedObjectAccessor.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method
 *
 * @param filterSpecs
 * @return list of object content
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 * @throws Exception
 */
private List<ObjectContent> retrievePropertiesAllObjects(
        List<PropertyFilterSpec> filterSpecs)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    RetrieveOptions retrieveOptions = new RetrieveOptions();
    ManagedObjectReference collector = serviceContent
            .getPropertyCollector();

    List<ObjectContent> contents = new ArrayList<ObjectContent>();

    RetrieveResult results = vimPort.retrievePropertiesEx(collector,
            filterSpecs, retrieveOptions);
    if (results != null && results.getObjects() != null
            && !results.getObjects().isEmpty()) {
        contents.addAll(results.getObjects());
    }
    String token = null;
    if (results != null && results.getToken() != null) {
        token = results.getToken();
    }
    while (token != null && token.length() > 0) {
        results = vimPort.continueRetrievePropertiesEx(collector, token);
        token = null;
        if (results != null) {
            token = results.getToken();
            if (results.getObjects() != null
                    && !results.getObjects().isEmpty()) {
                contents.addAll(results.getObjects());
            }
        }
    }

    return contents;
}
 
Example #14
Source File: VimAuthenticationHelper.java    From vsphere-automation-sdk-java with MIT License 5 votes vote down vote up
/**
 * Creates a session with the server using username and password
 *
 * @param server hostname or ip address of the server to log in to
 * @param username username for login
 * @param password password for login
 */
public void loginByUsernameAndPassword(
    String server, String username, String password) {
    try {
        String vimSdkUrl = "https://" + server + VIM_PATH;

        /*
         * Create a VimService object to obtain a VimPort binding provider.
         * The BindingProvider provides access to the protocol fields
         * in request/response messages. Retrieve the request context
         * which will be used for processing message requests.
         */
        this.vimService = new VimService();
        this.vimPort = vimService.getVimPort();
        Map<String, Object> ctxt =
                ((BindingProvider) vimPort).getRequestContext();

         /*
          * Store the Server URL in the request context and specify true
          * to maintain the connection between the client and server.
          * The client API will include the Server's HTTP cookie in its
          * requests to maintain the session. If you do not set this to
          * true, the Server will start a new session with each request.
          */
        ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vimSdkUrl);
        ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);

        // Retrieve the ServiceContent object and login
        this.serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);

        this.vimPort.login(
            serviceContent.getSessionManager(), username, password, null);

    } catch (InvalidLocaleFaultMsg | InvalidLoginFaultMsg | RuntimeFaultFaultMsg e) {
        e.printStackTrace();
    }
}
 
Example #15
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference getMorResourcePoolFromCluster(final ConnectionResources connectionResources, final ManagedObjectReference clusterMor,
                                                            final String resourcePoolName) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    if (isNotBlank(resourcePoolName)) {
        return new MorObjectHandler().getSpecificMor(connectionResources, clusterMor,
                ManagedObjectType.RESOURCE_POOL.getValue(), resourcePoolName);
    } else {
        return new MorObjectHandler().getSpecificMor(connectionResources, clusterMor,
                ManagedObjectType.RESOURCE_POOL.getValue(), ManagedObjectType.RESOURCES.getValue());
    }
}
 
Example #16
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private ManagedObjectReference getDataCenterMor(String dataCenterName, ManagedObjectReference mor, MoRefHandler moRefHandler)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    ManagedObjectReference dataCenterMor = moRefHandler.inContainerByType(mor, ManagedObjectType.DATA_CENTER.getValue())
            .get(dataCenterName);
    if (dataCenterMor == null) {
        throw new RuntimeException("Datacenter [" + dataCenterName + "] not found.");
    }

    return dataCenterMor;
}
 
Example #17
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@NotNull
private ManagedObjectReference getManagedObjectReference(String resourceName, ConnectionResources connectionResources,
                                                         String filter, String errorMessage) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference reference = connectionResources.getMorRootFolder();
    ManagedObjectReference managedObjectReference = new MorObjectHandler().getSpecificMor(connectionResources, reference,
            filter, resourceName);
    if (managedObjectReference == null) {
        throw new RuntimeException(errorMessage);
    }
    return managedObjectReference;
}
 
Example #18
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference getMorDataStore(String dataStoreName, ConnectionResources connectionResources,
                                              ManagedObjectReference vmMor, VmInputs vmInputs)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference dataStore = null;
    if (isNotBlank(dataStoreName)) {
        ManagedObjectReference cloneHostMor = getMorHost(vmInputs.getCloneHost(), connectionResources, vmMor);
        ConfigTarget configTarget = getHostConfigTarget(connectionResources, cloneHostMor);
        List<VirtualMachineDatastoreInfo> dataStoreInfoList = configTarget.getDatastore();
        for (VirtualMachineDatastoreInfo dataStoreInfo : dataStoreInfoList) {
            if (vmInputs.getCloneDataStore().equals(dataStoreInfo.getDatastore().getName())) {
                dataStore = getDataStoreRef(vmInputs.getCloneDataStore(), dataStoreInfoList);
                break;
            }
        }

        if (dataStore == null) {
            throw new RuntimeException(ErrorMessages.DATA_STORE_NOT_FOUND);
        }
    } else {
        ObjectContent[] objectContents = GetObjectProperties.getObjectProperties(connectionResources, vmMor,
                new String[]{ManagedObjectType.SUMMARY.getValue()});

        for (ObjectContent objectItem : objectContents) {
            List<DynamicProperty> vmProperties = objectItem.getPropSet();
            for (DynamicProperty propertyItem : vmProperties) {
                VirtualMachineSummary virtualMachineSummary = (VirtualMachineSummary) propertyItem.getVal();
                String vmPathName = virtualMachineSummary.getConfig().getVmPathName();
                dataStoreName = vmPathName.substring(1, vmPathName.indexOf(Constants.RIGHT_SQUARE_BRACKET));
                dataStore = getDataStore(dataStoreName, connectionResources, vmMor);
                break;
            }
            break;
        }
    }
    return dataStore;
}
 
Example #19
Source File: VMwareClient.java    From development with Apache License 2.0 5 votes vote down vote up
public ManagedObjectReference getVirtualMachine(String vmName)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    ManagedObjectReference vm = getServiceUtil().getDecendentMoRef(null,
            MO_TYPE_VIRTUAL_MACHINE, vmName);
    return vm;
}
 
Example #20
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
ConfigTarget getHostConfigTarget(ConnectionResources connectionResources, ManagedObjectReference hostMor)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    ManagedObjectReference environmentBrowserMor = new MorObjectHandler()
            .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue());
    ConfigTarget configTarget = connectionResources.getVimPortType().queryConfigTarget(environmentBrowserMor, hostMor);
    if (configTarget == null) {
        throw new RuntimeException(ErrorMessages.CONFIG_TARGET_NOT_FOUND_IN_COMPUTE_RESOURCE);
    }

    return configTarget;
}
 
Example #21
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private ManagedObjectReference getDataStore(String dataStoreName, ConnectionResources connectionResources,
                                            ManagedObjectReference vmMor) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ArrayOfManagedObjectReference dataStoresArray = (ArrayOfManagedObjectReference) new MorObjectHandler()
            .getObjectProperties(connectionResources, vmMor, ManagedObjectType.DATA_STORE.getValue());
    List<ManagedObjectReference> dataStores = dataStoresArray.getManagedObjectReference();
    for (ManagedObjectReference dataStore : dataStores) {
        DatastoreSummary datastoreSummary = (DatastoreSummary) new MorObjectHandler()
                .getObjectProperties(connectionResources, dataStore, ManagedObjectType.SUMMARY.getValue());
        if (dataStoreName.equalsIgnoreCase(datastoreSummary.getName())) {
            return dataStore;
        }
    }
    return null;
}
 
Example #22
Source File: ClusterComputeResourceServiceTest.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteVmGroupThrowsException() throws Exception {
    vmGroupMockInitializationOnExceptionThrown();
    VmInputs vmInputs = getVmInputs();
    when(vimPortMock.reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class)))
            .thenThrow(new RuntimeFaultFaultMsg(CLUSTER_CONFIGURATION_FAILED, new RuntimeFault()));
    thrownException.expectMessage(CLUSTER_CONFIGURATION_FAILED);

    clusterComputeResourceService.deleteVmGroup(httpInputsMock, vmInputs);
}
 
Example #23
Source File: ClusterComputeResourceServiceTest.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
@Test
public void createVmGroupThrowsException() throws Exception {
    vmGroupMockInitializationOnExceptionThrown();
    VmInputs vmInputs = getVmInputs();
    List<String> vmList = getList();
    when(vimPortMock.reconfigureComputeResourceTask(any(ManagedObjectReference.class), any(ClusterConfigSpecEx.class), any(Boolean.class)))
            .thenThrow(new RuntimeFaultFaultMsg(CLUSTER_CONFIGURATION_FAILED, new RuntimeFault()));
    thrownException.expectMessage(CLUSTER_CONFIGURATION_FAILED);

    clusterComputeResourceService.createVmGroup(httpInputsMock, vmInputs, vmList);
}
 
Example #24
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private ManagedObjectReference getComputeResourceMor(MoRefHandler moRefHandler, ManagedObjectReference hostMor)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    ManagedObjectReference computeResourceMor = (ManagedObjectReference) moRefHandler
            .entityProps(hostMor, new String[]{ManagedObjectType.PARENT.getValue()}).get(ManagedObjectType.PARENT.getValue());

    if (computeResourceMor == null) {
        throw new RuntimeException(ErrorMessages.COMPUTE_RESOURCE_NOT_FOUND_ON_HOST);
    }

    return computeResourceMor;
}
 
Example #25
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private ManagedObjectReference getHostMor(String hostname, MoRefHandler moRefHandler, ManagedObjectReference dataCenterMor)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    ManagedObjectReference hostMor = moRefHandler.inContainerByType(dataCenterMor, ManagedObjectType.HOST_SYSTEM.getValue())
            .get(hostname);
    if (hostMor == null) {
        throw new RuntimeException("Host [" + hostname + "] not found.");
    }

    return hostMor;
}
 
Example #26
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the helper object on the current connection at invocation time. Do not initialize on construction
 * since the connection may not be ready yet.
 */

private RetrieveResult containerViewByType(final ManagedObjectReference container,
                                           final String morefType,
                                           final RetrieveOptions retrieveOptions
) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    return this.containerViewByType(container, morefType, retrieveOptions, ManagedObjectType.NAME.getValue());
}
 
Example #27
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void setHostMor(VmInputs vmInputs) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference hostMor = null;
    if (dataCenterMor != null) {
        hostMor = getHostMor(vmInputs.getHostname(), moRefHandler, dataCenterMor);
    }
    this.setHostMor(hostMor);
}
 
Example #28
Source File: MoRefHandler.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private Map<String, ManagedObjectReference> toMap(RetrieveResult result)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    final Map<String, ManagedObjectReference> tgtMoref = new HashMap<>();

    String token = populate(result, tgtMoref);
    while (token != null && !token.isEmpty()) {
        // fetch results based on new token
        result = vimPort.continueRetrievePropertiesEx(serviceContent.getPropertyCollector(), token);
        token = populate(result, tgtMoref);
    }

    return tgtMoref;
}
 
Example #29
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void setComputeResourceMor() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference computeResourceMor = null;
    if (hostMor != null) {
        computeResourceMor = getComputeResourceMor(moRefHandler, hostMor);
    }
    this.setComputeResourceMor(computeResourceMor);
}
 
Example #30
Source File: ConnectionResources.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void setDataCenterMor(VmInputs vmInputs) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference dataCenterMor = null;
    if (StringUtils.isNotBlank(vmInputs.getDataCenterName())) {
        dataCenterMor = getDataCenterMor(vmInputs.getDataCenterName(), morRootFolder, moRefHandler);
    }
    this.setDataCenterMor(dataCenterMor);
}