3131
3232import javax .ejb .Local ;
3333import javax .mail .Authenticator ;
34- import javax .mail .Message .RecipientType ;
3534import javax .mail .MessagingException ;
3635import javax .mail .PasswordAuthentication ;
3736import javax .mail .Session ;
3837import javax .mail .URLName ;
38+ import javax .mail .Message .RecipientType ;
3939import javax .mail .internet .InternetAddress ;
4040import javax .naming .ConfigurationException ;
4141
5353import com .cloud .dc .ClusterVO ;
5454import com .cloud .dc .DataCenterVO ;
5555import com .cloud .dc .HostPodVO ;
56+ import com .cloud .dc .Vlan .VlanType ;
5657import com .cloud .dc .dao .ClusterDao ;
5758import com .cloud .dc .dao .DataCenterDao ;
5859import com .cloud .dc .dao .DataCenterIpAddressDao ;
59- import com .cloud .dc .dao .DataCenterVnetDaoImpl ;
6060import com .cloud .dc .dao .HostPodDao ;
6161import com .cloud .host .Host ;
6262import com .cloud .host .HostVO ;
63- import com .cloud .host .Status ;
6463import com .cloud .host .dao .HostDao ;
6564import com .cloud .network .dao .IPAddressDao ;
66- import com .cloud .service .ServiceOfferingVO ;
67- import com .cloud .service .dao .ServiceOfferingDao ;
6865import com .cloud .storage .StorageManager ;
6966import com .cloud .storage .StoragePoolVO ;
7067import com .cloud .storage .dao .StoragePoolDao ;
7572import com .cloud .utils .component .Inject ;
7673import com .cloud .utils .db .DB ;
7774import com .cloud .utils .db .SearchCriteria ;
78- import com .cloud .utils .db .Transaction ;
7975import com .sun .mail .smtp .SMTPMessage ;
8076import com .sun .mail .smtp .SMTPSSLTransport ;
8177import com .sun .mail .smtp .SMTPTransport ;
@@ -114,6 +110,8 @@ public class AlertManagerImpl implements AlertManager {
114110 private double _publicIPCapacityThreshold = 0.75 ;
115111 private double _privateIPCapacityThreshold = 0.75 ;
116112 private double _secondaryStorageCapacityThreshold = 0.75 ;
113+ private double _vlanCapacityThreshold = 0.75 ;
114+ private double _directNetworkPublicIpCapacityThreshold = 0.75 ;
117115 Map <Short ,Double > _capacityTypeThresholdMap = new HashMap <Short , Double >();
118116
119117 @ Override
@@ -157,7 +155,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
157155 String storageAllocCapacityThreshold = configs .get ("storage.allocated.capacity.threshold" );
158156 String publicIPCapacityThreshold = configs .get ("public.ip.capacity.threshold" );
159157 String privateIPCapacityThreshold = configs .get ("private.ip.capacity.threshold" );
160- String secondaryStorageCapacityThreshold = configs .get ("secondarystorage.capacity.threshold" );
158+ String secondaryStorageCapacityThreshold = configs .get ("secondarystorage.capacity.threshold" );
159+ String vlanCapacityThreshold = configs .get ("vlan.capacity.threshold" );
160+ String directNetworkPublicIpCapacityThreshold = configs .get ("directnetwork.public.ip.capacity.threshold" );
161161
162162 if (storageCapacityThreshold != null ) {
163163 _storageCapacityThreshold = Double .parseDouble (storageCapacityThreshold );
@@ -180,14 +180,22 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
180180 if (secondaryStorageCapacityThreshold != null ) {
181181 _secondaryStorageCapacityThreshold = Double .parseDouble (secondaryStorageCapacityThreshold );
182182 }
183+ if (vlanCapacityThreshold != null ) {
184+ _vlanCapacityThreshold = Double .parseDouble (vlanCapacityThreshold );
185+ }
186+ if (directNetworkPublicIpCapacityThreshold != null ) {
187+ _directNetworkPublicIpCapacityThreshold = Double .parseDouble (directNetworkPublicIpCapacityThreshold );
188+ }
183189
184190 _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_STORAGE , _storageCapacityThreshold );
185191 _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED , _storageAllocCapacityThreshold );
186192 _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_CPU , _cpuCapacityThreshold );
187193 _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_MEMORY , _memoryCapacityThreshold );
188- _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_PUBLIC_IP , _publicIPCapacityThreshold );
194+ _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP , _publicIPCapacityThreshold );
189195 _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_PRIVATE_IP , _privateIPCapacityThreshold );
190196 _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_SECONDARY_STORAGE , _secondaryStorageCapacityThreshold );
197+ _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_VLAN , _vlanCapacityThreshold );
198+ _capacityTypeThresholdMap .put (Capacity .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP , _directNetworkPublicIpCapacityThreshold );
191199
192200 String capacityCheckPeriodStr = configs .get ("capacity.check.period" );
193201 if (capacityCheckPeriodStr != null ) {
@@ -291,10 +299,15 @@ public void recalculateCapacity() {
291299 //ideal way would be to remove out the vlan param, and filter only on dcId
292300 //implementing the same
293301
294- // Calculate new Public IP capacity
295- s_logger .trace ("Executing public ip capacity update" );
296- createOrUpdateIpCapacity (dcId , null , CapacityVO .CAPACITY_TYPE_PUBLIC_IP );
297- s_logger .trace ("Done with public ip capacity update" );
302+ // Calculate new Public IP capacity for Virtual Network
303+ s_logger .trace ("Executing public ip capacity update for Virtual Network" );
304+ createOrUpdateIpCapacity (dcId , null , CapacityVO .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP );
305+ s_logger .trace ("Done with public ip capacity update for Virtual Network" );
306+
307+ // Calculate new Public IP capacity for Direct Attached Network
308+ s_logger .trace ("Executing public ip capacity update for Direct Attached Network" );
309+ createOrUpdateIpCapacity (dcId , null , CapacityVO .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP );
310+ s_logger .trace ("Done with public ip capacity update for Direct Attached Network" );
298311
299312 //Calculate VLAN's capacity
300313 s_logger .trace ("Executing VLAN capacity update" );
@@ -364,9 +377,12 @@ public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType){
364377 if (capacityType == CapacityVO .CAPACITY_TYPE_PRIVATE_IP ){
365378 totalIPs = _privateIPAddressDao .countIPs (podId , dcId , false );
366379 allocatedIPs = _privateIPAddressDao .countIPs (podId , dcId , true );
367- }else {
368- totalIPs = _publicIPAddressDao .countIPsForDashboard (dcId , false );
369- allocatedIPs = _publicIPAddressDao .countIPsForDashboard (dcId , true );
380+ }else if (capacityType == CapacityVO .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP ){
381+ totalIPs = _publicIPAddressDao .countIPsForNetwork (dcId , false , VlanType .VirtualNetwork );
382+ allocatedIPs = _publicIPAddressDao .countIPsForNetwork (dcId , true , VlanType .VirtualNetwork );
383+ }else {
384+ totalIPs = _publicIPAddressDao .countIPsForNetwork (dcId , false , VlanType .DirectAttached );
385+ allocatedIPs = _publicIPAddressDao .countIPsForNetwork (dcId , true , VlanType .DirectAttached );
370386 }
371387
372388 if (capacities .size () == 0 ){
@@ -416,6 +432,9 @@ public void checkForAlerts(){
416432 for (DataCenterVO dc : dataCenterList ){
417433 for (Short capacityType : dataCenterCapacityTypes ){
418434 List <SummedCapacity > capacity = _capacityDao .findCapacityBy (capacityType .intValue (), dc .getId (), null , null );
435+ if (capacity == null || capacity .size () == 0 ){
436+ continue ;
437+ }
419438 double totalCapacity = capacity .get (0 ).getTotalCapacity ();
420439 double usedCapacity = capacity .get (0 ).getUsedCapacity ();
421440 if (totalCapacity != 0 && usedCapacity /totalCapacity > _capacityTypeThresholdMap .get (capacityType )){
@@ -428,6 +447,9 @@ public void checkForAlerts(){
428447 for ( HostPodVO pod : podList ){
429448 for (Short capacityType : podCapacityTypes ){
430449 List <SummedCapacity > capacity = _capacityDao .findCapacityBy (capacityType .intValue (), pod .getDataCenterId (), pod .getId (), null );
450+ if (capacity == null || capacity .size () == 0 ){
451+ continue ;
452+ }
431453 double totalCapacity = capacity .get (0 ).getTotalCapacity ();
432454 double usedCapacity = capacity .get (0 ).getUsedCapacity ();
433455 if (totalCapacity != 0 && usedCapacity /totalCapacity > _capacityTypeThresholdMap .get (capacityType )){
@@ -441,6 +463,9 @@ public void checkForAlerts(){
441463 for ( ClusterVO cluster : clusterList ){
442464 for (Short capacityType : clusterCapacityTypes ){
443465 List <SummedCapacity > capacity = _capacityDao .findCapacityBy (capacityType .intValue (), cluster .getDataCenterId (), null , cluster .getId ());
466+ if (capacity == null || capacity .size () == 0 ){
467+ continue ;
468+ }
444469 double totalCapacity = capacity .get (0 ).getTotalCapacity ();
445470 double usedCapacity = capacity .get (0 ).getUsedCapacity ();
446471 if (totalCapacity != 0 && usedCapacity /totalCapacity > _capacityTypeThresholdMap .get (capacityType )){
@@ -485,7 +510,7 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
485510 usedStr = formatBytesToMegabytes (usedCapacity );
486511 msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)" ;
487512 break ;
488- case CapacityVO .CAPACITY_TYPE_PUBLIC_IP :
513+ case CapacityVO .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP :
489514 msgSubject = "System Alert: Number of unallocated public IPs is low in availablity zone " + dc .getName ();
490515 totalStr = Double .toString (totalCapacity );
491516 usedStr = Double .toString (usedCapacity );
@@ -497,6 +522,13 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
497522 usedStr = Double .toString (usedCapacity );
498523 msgContent = "Number of unallocated private IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
499524 break ;
525+
526+ case CapacityVO .CAPACITY_TYPE_SECONDARY_STORAGE :
527+ msgSubject = "System Alert: Low Available Storage in availablity zone " + dc .getName ();
528+ totalStr = Double .toString (totalCapacity );
529+ usedStr = Double .toString (usedCapacity );
530+ msgContent = "Available secondary storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)" ;
531+ break ;
500532 }
501533
502534 try {
@@ -509,8 +541,10 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
509541 private List <Short > getCapacityTypesAtZoneLevel (){
510542
511543 List <Short > dataCenterCapacityTypes = new ArrayList <Short >();
512- dataCenterCapacityTypes .add (Capacity .CAPACITY_TYPE_PUBLIC_IP );
544+ dataCenterCapacityTypes .add (Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP );
545+ dataCenterCapacityTypes .add (Capacity .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP );
513546 dataCenterCapacityTypes .add (Capacity .CAPACITY_TYPE_SECONDARY_STORAGE );
547+ dataCenterCapacityTypes .add (Capacity .CAPACITY_TYPE_VLAN );
514548 return dataCenterCapacityTypes ;
515549
516550 }
0 commit comments