Search in sources :

Example 11 with DetailVO

use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.

the class NiciraNvpElement method addNiciraNvpDevice.

@Override
@DB
public NiciraNvpDeviceVO addNiciraNvpDevice(final AddNiciraNvpDeviceCmd cmd) {
    final ServerResource resource = new NiciraNvpResource();
    final String deviceName = Network.Provider.NiciraNvp.getName();
    final NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    if (networkDevice == null) {
        throw new CloudRuntimeException("No network device found for " + deviceName);
    }
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    final long zoneId = physicalNetwork.getDataCenterId();
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
    } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
    }
    if (niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A NiciraNvp device is already configured on this physical network");
    }
    final Map<String, String> params = new HashMap<>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "Nicira Controller - " + cmd.getHost());
    params.put("ip", cmd.getHost());
    params.put("adminuser", cmd.getUsername());
    params.put("adminpass", cmd.getPassword());
    params.put("transportzoneuuid", cmd.getTransportzoneUuid());
    // FIXME What to do with multiple isolation types
    params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase());
    if (cmd.getL3GatewayServiceUuid() != null) {
        params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
    }
    final Map<String, Object> hostdetails = new HashMap<>();
    hostdetails.putAll(params);
    try {
        resource.configure(cmd.getHost(), hostdetails);
        final Host host = resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<NiciraNvpDeviceVO>() {

                @Override
                public NiciraNvpDeviceVO doInTransaction(final TransactionStatus status) {
                    final NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
                    niciraNvpDao.persist(niciraNvpDevice);
                    final DetailVO detail = new DetailVO(host.getId(), "niciranvpdeviceid", String.valueOf(niciraNvpDevice.getId()));
                    hostDetailsDao.persist(detail);
                    return niciraNvpDevice;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add Nicira Nvp Device due to internal error.");
        }
    } catch (final ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ServerResource(com.cloud.resource.ServerResource) NiciraNvpResource(com.cloud.network.resource.NiciraNvpResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DB(com.cloud.utils.db.DB)

Example 12 with DetailVO

use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.

the class FirstFitAllocator method getHostGuestOSCategory.

protected String getHostGuestOSCategory(final Host host) {
    final DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), "guest.os.category.id");
    if (hostDetail != null) {
        final String guestOSCategoryIdString = hostDetail.getValue();
        final long guestOSCategoryId;
        try {
            guestOSCategoryId = Long.parseLong(guestOSCategoryIdString);
        } catch (final Exception e) {
            return null;
        }
        final GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
        if (guestOSCategory != null) {
            return guestOSCategory.getName();
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : DetailVO(com.cloud.host.DetailVO) GuestOSCategoryVO(com.cloud.storage.GuestOSCategoryVO) ConfigurationException(javax.naming.ConfigurationException)

Example 13 with DetailVO

use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method getGuestOSCategoryId.

@Override
public Long getGuestOSCategoryId(final long hostId) {
    final HostVO host = _hostDao.findById(hostId);
    if (host == null) {
        return null;
    } else {
        _hostDao.loadDetails(host);
        final DetailVO detail = _hostDetailsDao.findDetail(hostId, "guest.os.category.id");
        if (detail == null) {
            return null;
        } else {
            return Long.parseLong(detail.getValue());
        }
    }
}
Also used : DetailVO(com.cloud.host.DetailVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Example 14 with DetailVO

use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method updateHost.

@Override
public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
    final Long hostId = cmd.getId();
    final Long guestOSCategoryId = cmd.getOsCategoryId();
    // Verify that the host exists
    final HostVO host = _hostDao.findById(hostId);
    if (host == null) {
        throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
    }
    if (cmd.getAllocationState() != null) {
        final ResourceState.Event resourceEvent = ResourceState.Event.toEvent(cmd.getAllocationState());
        if (resourceEvent != ResourceState.Event.Enable && resourceEvent != ResourceState.Event.Disable) {
            throw new CloudRuntimeException("Invalid allocation state:" + cmd.getAllocationState() + ", only Enable/Disable are allowed");
        }
        resourceStateTransitTo(host, resourceEvent, _nodeId);
    }
    if (guestOSCategoryId != null) {
        // Verify that the guest OS Category exists
        if (!(guestOSCategoryId > 0) || _guestOSCategoryDao.findById(guestOSCategoryId) == null) {
            throw new InvalidParameterValueException("Please specify a valid guest OS category.");
        }
        final GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
        final DetailVO guestOSDetail = _hostDetailsDao.findDetail(hostId, "guest.os.category.id");
        if (guestOSCategory != null && !GuestOSCategoryVO.CATEGORY_NONE.equalsIgnoreCase(guestOSCategory.getName())) {
            // Create/Update an entry for guest.os.category.id
            if (guestOSDetail != null) {
                guestOSDetail.setValue(String.valueOf(guestOSCategory.getId()));
                _hostDetailsDao.update(guestOSDetail.getId(), guestOSDetail);
            } else {
                final Map<String, String> detail = new HashMap<>();
                detail.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
                _hostDetailsDao.persist(hostId, detail);
            }
        } else {
            // Delete any existing entry for guest.os.category.id
            if (guestOSDetail != null) {
                _hostDetailsDao.remove(guestOSDetail.getId());
            }
        }
    }
    final List<String> hostTags = cmd.getHostTags();
    if (hostTags != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Updating Host Tags to :" + hostTags);
        }
        _hostTagsDao.persist(hostId, hostTags);
    }
    final String url = cmd.getUrl();
    if (url != null) {
        _storageMgr.updateSecondaryStorage(cmd.getId(), cmd.getUrl());
    }
    final HostVO updatedHost = _hostDao.findById(hostId);
    return updatedHost;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) GuestOSCategoryVO(com.cloud.storage.GuestOSCategoryVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Example 15 with DetailVO

use of com.cloud.host.DetailVO in project cloudstack by apache.

the class CloudZonesStartupProcessor method updateHostDetails.

private void updateHostDetails(HostVO host, StartupRoutingCommand startupRoutingCmd) {
    final String name = "supportsResign";
    final String value = String.valueOf(startupRoutingCmd.getSupportsClonedVolumes());
    DetailVO hostDetail = hostDetailsDao.findDetail(host.getId(), name);
    if (hostDetail != null) {
        hostDetail.setValue(value);
        hostDetailsDao.update(hostDetail.getId(), hostDetail);
    } else {
        hostDetail = new DetailVO(host.getId(), name, value);
        hostDetailsDao.persist(hostDetail);
    }
}
Also used : DetailVO(com.cloud.host.DetailVO)

Aggregations

DetailVO (com.cloud.host.DetailVO)38 HostVO (com.cloud.host.HostVO)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)13 TransactionStatus (com.cloud.utils.db.TransactionStatus)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 ConfigurationException (javax.naming.ConfigurationException)13 HashMap (java.util.HashMap)12 Host (com.cloud.host.Host)9 DB (com.cloud.utils.db.DB)9 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)8 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)8 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)7 NetworkDevice (org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice)6 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)5 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 ServerResource (com.cloud.resource.ServerResource)5 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)5 GuestOSCategoryVO (com.cloud.storage.GuestOSCategoryVO)4 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)4