-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSecurityManagerMBeanImpl.java
More file actions
149 lines (123 loc) · 4.58 KB
/
SecurityManagerMBeanImpl.java
File metadata and controls
149 lines (123 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.security;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.management.StandardMBean;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.security.LocalSecurityGroupWorkQueue.LocalSecurityGroupWork;
import com.cloud.network.security.SecurityGroupWork.Step;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine.Type;
public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityGroupManagerMBean, RuleUpdateLog {
SecurityGroupManagerImpl2 _sgMgr;
boolean _monitoringEnabled = false;
//keep track of last scheduled, last update sent and last seqno sent per vm. Make it available over JMX
Map<Long, Date> _scheduleTimestamps = new ConcurrentHashMap<Long, Date>(4000, 100, 64);
Map<Long, Date> _updateTimestamps = new ConcurrentHashMap<Long, Date>(4000, 100, 64);
protected SecurityManagerMBeanImpl(SecurityGroupManagerImpl2 securityGroupManager) {
super(SecurityGroupManagerMBean.class, false);
this._sgMgr = securityGroupManager;
}
@Override
public int getQueueSize() {
return this._sgMgr.getQueueSize();
}
@Override
public void logUpdateDetails(Long vmId, Long seqno) {
if (_monitoringEnabled) {
_updateTimestamps.put(vmId, new Date());
}
}
@Override
public void logScheduledDetails(Set<Long> vmIds) {
if (_monitoringEnabled) {
for (Long vmId : vmIds) {
_scheduleTimestamps.put(vmId, new Date());
}
}
}
@Override
public void enableUpdateMonitor(boolean enable) {
_monitoringEnabled = enable;
if (!enable) {
_updateTimestamps.clear();
_scheduleTimestamps.clear();
}
}
@Override
public Map<Long, Date> getScheduledTimestamps() {
return _scheduleTimestamps;
}
@Override
public Map<Long, Date> getLastUpdateSentTimestamps() {
return _updateTimestamps;
}
@Override
public List<Long> getVmsInQueue() {
return _sgMgr.getWorkQueue().getVmsInQueue();
}
@Override
public void disableSchedulerForVm(Long vmId) {
_sgMgr.disableSchedulerForVm(vmId, true);
}
@Override
public void enableSchedulerForVm(Long vmId) {
_sgMgr.disableSchedulerForVm(vmId, false);
}
@Override
public Long[] getDisabledVmsForScheduler() {
return _sgMgr.getDisabledVmsForScheduler();
}
@Override
public void enableSchedulerForAllVms() {
_sgMgr.enableAllVmsForScheduler();
}
@Override
public void scheduleRulesetUpdateForVm(Long vmId) {
List<Long> affectedVms = new ArrayList<Long>(1);
affectedVms.add(vmId);
_sgMgr.scheduleRulesetUpdateToHosts(affectedVms, true, null);
}
@Override
public void tryRulesetUpdateForVmBypassSchedulerVeryDangerous(Long vmId, Long seqno) {
LocalSecurityGroupWork work = new LocalSecurityGroupWorkQueue.LocalSecurityGroupWork(vmId, seqno, Step.Scheduled);
_sgMgr.sendRulesetUpdates(work);
}
@Override
public void simulateVmStart(Long vmId) {
//all we need is the vmId
VMInstanceVO vm = new VMInstanceVO(vmId, 5, "foo", "foo", Type.User, null, HypervisorType.Any, 8, 1, 1, false, false, null);
_sgMgr.handleVmStarted(vm);
}
@Override
public void disableSchedulerEntirelyVeryDangerous(boolean disable) {
_sgMgr.disableScheduler(disable);
}
@Override
public boolean isSchedulerDisabledEntirely() {
return _sgMgr.isSchedulerDisabled();
}
@Override
public void clearSchedulerQueueVeryDangerous() {
_sgMgr.clearWorkQueue();
}
}