use of com.cloud.dc.HostPodVO in project cloudstack by apache.
the class AlertGenerator method publishAlertOnEventBus.
public static void publishAlertOnEventBus(String alertType, long dataCenterId, Long podId, String subject, String body) {
String configKey = Config.PublishAlertEvent.key();
String value = s_configDao.getValue(configKey);
boolean configValue = Boolean.parseBoolean(value);
if (!configValue)
return;
try {
s_eventBus = ComponentContext.getComponent(EventBus.class);
} catch (NoSuchBeanDefinitionException nbe) {
// no provider is configured to provide events bus, so just return
return;
}
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, EventCategory.ALERT_EVENT.getName(), alertType, null, null);
Map<String, String> eventDescription = new HashMap<String, String>();
DataCenterVO dc = s_dcDao.findById(dataCenterId);
HostPodVO pod = s_podDao.findById(podId);
eventDescription.put("event", alertType);
if (dc != null) {
eventDescription.put("dataCenterId", dc.getUuid());
} else {
eventDescription.put("dataCenterId", null);
}
if (pod != null) {
eventDescription.put("podId", pod.getUuid());
} else {
eventDescription.put("podId", null);
}
eventDescription.put("subject", subject);
eventDescription.put("body", body);
String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
eventDescription.put("eventDateTime", eventDate);
event.setDescription(eventDescription);
try {
s_eventBus.publish(event);
} catch (EventBusException e) {
s_logger.warn("Failed to publish alert on the the event bus.");
}
}
use of com.cloud.dc.HostPodVO in project cloudstack by apache.
the class CloudZonesStartupProcessor method updateSecondaryHost.
protected void updateSecondaryHost(final HostVO host, final StartupStorageCommand startup, final Host.Type type) throws AgentAuthnException {
String zoneToken = startup.getDataCenter();
if (zoneToken == null) {
s_logger.warn("No Zone Token passed in, cannot not find zone for the agent");
throw new AgentAuthnException("No Zone Token passed in, cannot not find zone for agent");
}
DataCenterVO zone = _zoneDao.findByToken(zoneToken);
if (zone == null) {
zone = _zoneDao.findByName(zoneToken);
if (zone == null) {
try {
long zoneId = Long.parseLong(zoneToken);
zone = _zoneDao.findById(zoneId);
if (zone == null) {
throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
}
} catch (NumberFormatException nfe) {
throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
}
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Successfully loaded the DataCenter from the zone token passed in ");
}
// yes, routing
HostPodVO pod = findPod(startup, zone.getId(), Host.Type.Routing);
Long podId = null;
if (pod != null) {
s_logger.debug("Found pod " + pod.getName() + " for the secondary storage host " + startup.getName());
podId = pod.getId();
}
host.setDataCenterId(zone.getId());
host.setPodId(podId);
host.setClusterId(null);
host.setPrivateIpAddress(startup.getPrivateIpAddress());
host.setPrivateNetmask(startup.getPrivateNetmask());
host.setPrivateMacAddress(startup.getPrivateMacAddress());
host.setPublicIpAddress(startup.getPublicIpAddress());
host.setPublicMacAddress(startup.getPublicMacAddress());
host.setPublicNetmask(startup.getPublicNetmask());
host.setStorageIpAddress(startup.getStorageIpAddress());
host.setStorageMacAddress(startup.getStorageMacAddress());
host.setStorageNetmask(startup.getStorageNetmask());
host.setVersion(startup.getVersion());
host.setName(startup.getName());
host.setType(type);
host.setStorageUrl(startup.getIqn());
host.setLastPinged(System.currentTimeMillis() >> 10);
host.setCaps(null);
host.setCpus(null);
host.setTotalMemory(0);
host.setSpeed(null);
host.setParent(startup.getParent());
host.setTotalSize(startup.getTotalSize());
host.setHypervisorType(HypervisorType.None);
if (startup.getNfsShare() != null) {
host.setStorageUrl(startup.getNfsShare());
}
}
use of com.cloud.dc.HostPodVO in project cloudstack by apache.
the class CloudZonesStartupProcessor method findPod.
private HostPodVO findPod(StartupCommand startup, long zoneId, Host.Type type) {
HostPodVO pod = null;
List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
for (HostPodVO hostPod : podsInZone) {
if (checkCIDR(type, hostPod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
pod = hostPod;
// found the default POD having the same subnet.
updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask());
break;
}
}
return pod;
}
use of com.cloud.dc.HostPodVO in project cloudstack by apache.
the class StorageNetworkManagerImpl method createIpRange.
@Override
@DB
public StorageNetworkIpRange createIpRange(final CreateStorageNetworkIpRangeCmd cmd) throws SQLException {
final Long podId = cmd.getPodId();
final String startIp = cmd.getStartIp();
String endIp = cmd.getEndIp();
final Integer vlan = cmd.getVlan();
final String netmask = cmd.getNetmask();
if (endIp == null) {
endIp = startIp;
}
if (!NetUtils.isValidIp4Netmask(netmask)) {
throw new CloudRuntimeException("Invalid netmask:" + netmask);
}
HostPodVO pod = _podDao.findById(podId);
if (pod == null) {
throw new CloudRuntimeException("Cannot find pod " + podId);
}
final Long zoneId = pod.getDataCenterId();
List<NetworkVO> nws = _networkDao.listByZoneAndTrafficType(zoneId, TrafficType.Storage);
if (nws.size() == 0) {
throw new CloudRuntimeException("Cannot find storage network in zone " + zoneId);
}
if (nws.size() > 1) {
throw new CloudRuntimeException("Find more than one storage network in zone " + zoneId + "," + nws.size() + " found");
}
final NetworkVO nw = nws.get(0);
checkOverlapPrivateIpRange(podId, startIp, endIp);
checkOverlapStorageIpRange(podId, startIp, endIp);
StorageNetworkIpRangeVO range = null;
final String endIpFinal = endIp;
return Transaction.execute(new TransactionCallbackWithException<StorageNetworkIpRangeVO, SQLException>() {
@Override
public StorageNetworkIpRangeVO doInTransaction(TransactionStatus status) throws SQLException {
StorageNetworkIpRangeVO range = new StorageNetworkIpRangeVO(zoneId, podId, nw.getId(), startIp, endIpFinal, vlan, netmask, cmd.getGateWay());
_sNwIpRangeDao.persist(range);
try {
createStorageIpEntires(TransactionLegacy.currentTxn(), range.getId(), startIp, endIpFinal, zoneId);
} catch (SQLException e) {
StringBuilder err = new StringBuilder();
err.append("Create storage network range failed.");
err.append("startIp=" + startIp);
err.append("endIp=" + endIpFinal);
err.append("netmask=" + netmask);
err.append("zoneId=" + zoneId);
s_logger.debug(err.toString(), e);
throw e;
}
return range;
}
});
}
use of com.cloud.dc.HostPodVO in project cloudstack by apache.
the class ConfigurationManagerImpl method createPod.
@Override
@DB
public HostPodVO createPod(final long userId, final String podName, final long zoneId, final String gateway, final String cidr, final String startIp, String endIp, final String allocationStateStr, final boolean skipGatewayOverlapCheck) {
// Check if the zone is valid
if (!validZone(zoneId)) {
throw new InvalidParameterValueException("Please specify a valid zone.");
}
// Check if zone is disabled
final DataCenterVO zone = _zoneDao.findById(zoneId);
final Account account = CallContext.current().getCallingAccount();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
}
final String cidrAddress = getCidrAddress(cidr);
final int cidrSize = getCidrSize(cidr);
// end ip of the pod's cidr
if (StringUtils.isNotEmpty(startIp)) {
if (endIp == null) {
endIp = NetUtils.getIpRangeEndIpFromCidr(cidrAddress, cidrSize);
}
}
// Validate new pod settings
checkPodAttributes(-1, podName, zoneId, gateway, cidr, startIp, endIp, allocationStateStr, true, skipGatewayOverlapCheck);
// Create the new pod in the database
String ipRange;
if (StringUtils.isNotEmpty(startIp)) {
ipRange = startIp + "-" + endIp + "-" + DefaultForSystemVmsForPodIpRange + "-" + DefaultVlanForPodIpRange;
} else {
throw new InvalidParameterValueException("Start ip is required parameter");
}
final HostPodVO podFinal = new HostPodVO(podName, zoneId, gateway, cidrAddress, cidrSize, ipRange);
Grouping.AllocationState allocationState = null;
if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
podFinal.setAllocationState(allocationState);
}
final String endIpFinal = endIp;
return Transaction.execute(new TransactionCallback<HostPodVO>() {
@Override
public HostPodVO doInTransaction(final TransactionStatus status) {
final HostPodVO pod = _podDao.persist(podFinal);
if (StringUtils.isNotEmpty(startIp)) {
_zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIpFinal, false, null);
}
final String[] linkLocalIpRanges = NetUtils.getLinkLocalIPRange(_configDao.getValue(Config.ControlCidr.key()));
if (linkLocalIpRanges != null) {
_zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]);
}
return pod;
}
});
}
Aggregations