use of com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand in project cosmic by MissionCriticalCloud.
the class SecondaryStorageManagerImpl method generateFirewallConfiguration.
@Override
public boolean generateFirewallConfiguration(final Long ssAHostId) {
if (ssAHostId == null) {
return true;
}
final HostVO ssAHost = this._hostDao.findById(ssAHostId);
final SecondaryStorageVmVO thisSecStorageVm = this._secStorageVmDao.findByInstanceName(ssAHost.getName());
if (thisSecStorageVm == null) {
logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
return false;
}
final String copyPort = this._useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
final SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getType(), Op.EQ, HostType.SecondaryStorageVM);
sc.and(sc.entity().getStatus(), Op.IN, HostStatus.Up, HostStatus.Connecting);
final List<HostVO> ssvms = sc.list();
for (final HostVO ssvm : ssvms) {
if (ssvm.getId() == ssAHostId) {
continue;
}
final Answer answer = this._agentMgr.easySend(ssvm.getId(), thiscpc);
if (answer != null && answer.getResult()) {
logger.debug("Successfully programmed firewall rules into SSVM " + ssvm.getName());
} else {
logger.debug("failed to program firewall rules into secondary storage vm : " + ssvm.getName());
return false;
}
}
final SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false);
for (final HostVO ssvm : ssvms) {
if (ssvm.getId() == ssAHostId) {
continue;
}
allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
}
final Answer answer = this._agentMgr.easySend(ssAHostId, allSSVMIpList);
if (answer != null && answer.getResult()) {
logger.debug("Successfully programmed firewall rules into " + thisSecStorageVm.getHostName());
} else {
logger.debug("failed to program firewall rules into secondary storage vm : " + thisSecStorageVm.getHostName());
return false;
}
return true;
}
use of com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand in project cosmic by MissionCriticalCloud.
the class RequestTest method testSerDeser.
@Test
@Ignore
public void testSerDeser() {
s_logger.info("Testing serializing and deserializing works as expected");
s_logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging");
final UpdateHostPasswordCommand cmd1 = new UpdateHostPasswordCommand("abc", "def");
s_logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level");
final SecStorageFirewallCfgCommand cmd2 = new SecStorageFirewallCfgCommand();
s_logger.info("GetHostStatsCommand should not show up at all in debug level");
final GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101);
cmd2.addPortConfig("abc", "24", true, "eth0");
cmd2.addPortConfig("127.0.0.1", "44", false, "eth1");
final Request sreq = new Request(2, 3, new Command[] { cmd1, cmd2, cmd3 }, true, true);
sreq.setSequence(892403717);
final Logger logger = LoggerFactory.getLogger(GsonHelper.class);
// logger.setLevel(Level.DEBUG);
String log = sreq.log("Debug", true);
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
assert (!log.contains(GetHostStatsCommand.class.getSimpleName()));
assert (!log.contains("username"));
assert (!log.contains("password"));
// logger.setLevel(Level.TRACE);
log = sreq.log("Trace", true);
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
assert (log.contains(GetHostStatsCommand.class.getSimpleName()));
assert (!log.contains("username"));
assert (!log.contains("password"));
// logger.setLevel(Level.INFO);
log = sreq.log("Info", true);
assert (log == null);
// logger.setLevel(level);
byte[] bytes = sreq.getBytes();
assert Request.getSequence(bytes) == 892403717;
assert Request.getManagementServerId(bytes) == 3;
assert Request.getAgentId(bytes) == 2;
assert Request.getViaAgentId(bytes) == 2;
Request creq = null;
try {
creq = Request.parse(bytes);
} catch (final ClassNotFoundException e) {
s_logger.error("Unable to parse bytes: ", e);
} catch (final UnsupportedVersionException e) {
s_logger.error("Unable to parse bytes: ", e);
}
assert creq != null : "Couldn't get the request back";
compareRequest(creq, sreq);
final Answer ans = new Answer(cmd1, true, "No Problem");
final Response cresp = new Response(creq, ans);
bytes = cresp.getBytes();
Response sresp = null;
try {
sresp = Response.parse(bytes);
} catch (final ClassNotFoundException e) {
s_logger.error("Unable to parse bytes: ", e);
} catch (final UnsupportedVersionException e) {
s_logger.error("Unable to parse bytes: ", e);
}
assert sresp != null : "Couldn't get the response back";
compareRequest(cresp, sresp);
}
Aggregations