Search in sources :

Example 1 with ExternalNetwork

use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.

the class BaseImportNetworksModel method onProviderChosen.

private void onProviderChosen() {
    final Provider<?> provider = providers.getSelectedItem();
    if (provider == null) {
        return;
    }
    startProgress();
    AsyncQuery<List<StoragePool>> dataCenterQuery = new AsyncQuery<>(returnValue -> {
        final List<StoragePool> dataCenters = new LinkedList<>(returnValue);
        Collections.sort(dataCenters, new NameableComparator());
        AsyncQuery<QueryReturnValue> externalNetworksQuery = new AsyncQuery<>(queryReturnValue -> {
            if (queryReturnValue.getSucceeded()) {
                Map<Network, Set<Guid>> externalNetworkToDataCenters = queryReturnValue.getReturnValue();
                providerNetworks.setItems(getExternalNetworks(externalNetworkToDataCenters, dataCenters));
                importedNetworks.setItems(new LinkedList<ExternalNetwork>());
            } else {
                final ErrorPopupManager popupManager = (ErrorPopupManager) TypeResolver.getInstance().resolve(ErrorPopupManager.class);
                popupManager.show(ConstantsManager.getInstance().getMessages().failedToListExternalNetworks(queryReturnValue.getExceptionMessage()));
            }
            stopProgress();
        }, true);
        AsyncDataProvider.getInstance().getExternalNetworksByProviderId(externalNetworksQuery, provider.getId());
    });
    AsyncDataProvider.getInstance().getDataCenterList(dataCenterQuery);
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Set(java.util.Set) NameableComparator(org.ovirt.engine.core.common.businessentities.comparators.NameableComparator) LinkedList(java.util.LinkedList) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) Network(org.ovirt.engine.core.common.businessentities.network.Network) ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork) ErrorPopupManager(org.ovirt.engine.ui.uicommonweb.ErrorPopupManager) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork)

Example 2 with ExternalNetwork

use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.

the class BaseImportNetworksModel method getExternalNetwork.

private ExternalNetwork getExternalNetwork(Network network, Set<Guid> attachedDataCenters, List<StoragePool> dataCenters) {
    ExternalNetwork externalNetwork = new ExternalNetwork();
    externalNetwork.setNetwork(network);
    externalNetwork.setDisplayName(network.getName());
    externalNetwork.setPublicUse(true);
    List<StoragePool> availableDataCenters = getAvailableDataCenters(dataCenters, attachedDataCenters);
    externalNetwork.getDataCenters().setItems(availableDataCenters);
    externalNetwork.getDataCenters().setSelectedItem(dataCenterListModel.getSelectedItem() != null && availableDataCenters.contains(dataCenterListModel.getSelectedItem()) ? dataCenterListModel.getSelectedItem() : Linq.firstOrNull(availableDataCenters));
    return externalNetwork;
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork)

Example 3 with ExternalNetwork

use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.

the class BaseImportNetworksModel method cancelImport.

private void cancelImport() {
    Collection<ExternalNetwork> selectedNetworks = getImportedNetworks().getSelectedItems();
    Collection<ExternalNetwork> importedNetworks = getImportedNetworks().getItems();
    getDefaultCommand().setIsExecutionAllowed(selectedNetworks.size() < importedNetworks.size());
    for (ExternalNetwork externalNetwork : selectedNetworks) {
        externalNetwork.setDisplayName(externalNetwork.getNetwork().getName());
    }
}
Also used : ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork)

Example 4 with ExternalNetwork

use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.

the class BaseImportNetworksModel method onImport.

public void onImport() {
    if (!validate()) {
        return;
    }
    List<ActionParametersBase> multipleActionParameters = new LinkedList<>();
    for (final ExternalNetwork externalNetwork : importedNetworks.getItems()) {
        final Network network = externalNetwork.getNetwork();
        final Guid dcId = externalNetwork.getDataCenters().getSelectedItem().getId();
        ImportExternalNetworkParameters params = new ImportExternalNetworkParameters(network.getProvidedBy().getProviderId(), network.getProvidedBy().getExternalId(), dcId, externalNetwork.isPublicUse(), true);
        multipleActionParameters.add(params);
    }
    Frontend.getInstance().runMultipleActions(ActionType.ImportExternalNetwork, multipleActionParameters, result -> sourceListModel.getSearchCommand().execute());
    cancel();
}
Also used : ImportExternalNetworkParameters(org.ovirt.engine.core.common.action.ImportExternalNetworkParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) LinkedList(java.util.LinkedList) ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork)

Example 5 with ExternalNetwork

use of org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork in project ovirt-engine by oVirt.

the class BaseImportNetworksModel method validate.

private boolean validate() {
    String errorDuplicate = ConstantsManager.getInstance().getConstants().importDuplicateName();
    boolean valid = true;
    Collection<ExternalNetwork> networks = importedNetworks.getItems();
    List<String> errors = new ArrayList<>(networks.size());
    Map<String, Integer> nameToIndex = new HashMap<>();
    int i = 0;
    for (ExternalNetwork network : networks) {
        String networkName = network.getDisplayName();
        Integer encounteredIndex = nameToIndex.get(networkName);
        // if this name has been encountered, invalidate that entry; else store it for future invalidation
        if (encounteredIndex != null) {
            errors.set(encounteredIndex, errorDuplicate);
            valid = false;
        } else {
            nameToIndex.put(networkName, i);
        }
        // invalidate current entry
        errors.add(encounteredIndex == null ? null : errorDuplicate);
        ++i;
    }
    getErrors().setItems(errors);
    return valid;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork)

Aggregations

ExternalNetwork (org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork)6 ArrayList (java.util.ArrayList)3 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Network (org.ovirt.engine.core.common.businessentities.network.Network)2 Context (com.google.gwt.cell.client.Cell.Context)1 GWT (com.google.gwt.core.client.GWT)1 EventBus (com.google.gwt.event.shared.EventBus)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 SafeHtmlUtils (com.google.gwt.safehtml.shared.SafeHtmlUtils)1 UiBinder (com.google.gwt.uibinder.client.UiBinder)1 UiField (com.google.gwt.uibinder.client.UiField)1 Column (com.google.gwt.user.cellview.client.Column)1 Inject (com.google.inject.Inject)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 ImportExternalNetworkParameters (org.ovirt.engine.core.common.action.ImportExternalNetworkParameters)1