public HostVO allocateNCCResourceForNetwork(Network guestConfig) throws ConfigurationException { Map<String, String> _configs; List<NetScalerControlCenterVO> ncc = _netscalerControlCenterDao.listAll(); HostVO hostVO = null; if (ncc.size() > 0) { NetScalerControlCenterVO nccVO = ncc.get(0); String ipAddress = nccVO.getNccip(); Map hostDetails = new HashMap<String, String>(); String hostName = "NetscalerControlCenter"; hostDetails.put("name", hostName); hostDetails.put("guid", UUID.randomUUID().toString()); hostDetails.put("zoneId", Long.toString(guestConfig.getDataCenterId())); hostDetails.put("ip", ipAddress); hostDetails.put("username", nccVO.getUsername()); hostDetails.put("password", DBEncryptionUtil.decrypt(nccVO.getPassword())); hostDetails.put("deviceName", "netscaler control center"); hostDetails.put("cmdTimeOut", Long.toString(NumbersUtil.parseInt(_configDao.getValue(Config.NCCCmdTimeOut.key()), 600000))); ServerResource resource = new NetScalerControlCenterResource(); resource.configure(hostName, hostDetails); final Host host = _resourceMgr.addHost(guestConfig.getDataCenterId(), resource, Host.Type.NetScalerControlCenter, hostDetails); hostVO = _hostDao.findById(host.getId()); } return hostVO; }
public Answer retry(final Command command, final Class<? extends Answer> answerClass, final Exception error) { if (commandsToRetry.containsKey(command)) { Integer numRetries = commandsToRetry.get(command); if (numRetries > ZERO) { commandsToRetry.put(command, --numRetries); s_logger.warn("Retrying " + command.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); return serverResource.executeRequest(command); } else { commandsToRetry.remove(command); } } try { final Constructor<? extends Answer> answerConstructor = answerClass.getConstructor(Command.class, Exception.class); return answerConstructor.newInstance(command, error); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { return Answer.createUnsupportedCommandAnswer(command); } } }
@Override public void disconnect(Status state) { if (s_logger.isDebugEnabled()) { s_logger.debug("Processing disconnect " + _id + "(" + _name + ")"); } for (ScheduledFuture<?> future : _futures) { future.cancel(false); } synchronized (this) { if (_resource != null) { _resource.disconnected(); _resource = null; } } }
@Override public ServerResource reloadResource(HostVO host) { String resourceName = host.getResource(); ServerResource resource = getResource(resourceName); if (resource != null) { _hostDao.loadDetails(host); updateNetworkLabels(host); HashMap<String, Object> params = buildConfigParams(host); try { resource.configure(host.getName(), params); } catch (ConfigurationException e) { s_logger.warn("Unable to configure resource due to " + e.getMessage()); return null; } if (!resource.start()) { s_logger.warn("Unable to start the resource"); return null; } } return resource; }
public Agent(final IAgentShell shell, final int localAgentId, final ServerResource resource) throws ConfigurationException { _shell = shell; _resource = resource; _link = null; resource.setAgentControl(this); final String value = _shell.getPersistentProperty(getResourceName(), "id"); _id = value != null ? Long.parseLong(value) : null; s_logger.info("id is " + (_id != null ? _id : "")); final Map<String, Object> params = PropertiesUtil.toMap(_shell.getProperties()); // merge with properties from command line to let resource access command line parameters for (final Map.Entry<String, Object> cmdLineProp : _shell.getCmdLineProperties().entrySet()) { params.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } if (!_resource.configure(getResourceName(), params)) { throw new ConfigurationException("Unable to configure " + _resource.getName()); } final String host = _shell.getNextHost(); _connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this); // ((NioClient)_connection).setBindAddress(_shell.getPrivateIp()); s_logger.debug("Adding shutdown hook"); Runtime.getRuntime().addShutdownHook(_shutdownThread); _ugentTaskPool = new ThreadPoolExecutor(shell.getPingRetries(), 2 * shell.getPingRetries(), 10, TimeUnit.MINUTES, new SynchronousQueue<Runnable>(), new NamedThreadFactory( "UgentTask")); _executor = new ThreadPoolExecutor(_shell.getWorkers(), 5 * _shell.getWorkers(), 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory( "agentRequest-Handler")); s_logger.info("Agent [id = " + (_id != null ? _id : "new") + " : type = " + getResourceName() + " : zone = " + _shell.getZone() + " : pod = " + _shell.getPod() + " : workers = " + _shell.getWorkers() + " : host = " + host + " : port = " + _shell.getPort()); }
final PingCommand ping = _resource.getCurrentStatus(getId()); final Request request = new Request(_id, -1, ping, false); request.setSequence(getNextSequence()); _inProgress.incrementAndGet(); try { answer = _resource.executeRequest(command); } finally { _inProgress.decrementAndGet();
cmds = resource.initialize(); if (cmds == null) { s_logger.info("Unable to fully initialize the agent because no StartupCommands are returned"); if (hostExists) { if (cmds != null) { resource.disconnected(); resource.disconnected();
} else if (cmd instanceof SetupCertificateCommand && ((SetupCertificateCommand) cmd).isHandleByAgent()) { answer = setupAgentCertificate((SetupCertificateCommand) cmd); if (Host.Type.Routing.equals(_resource.getType())) { scheduleServicesRestartTask(); answer = _resource.executeRequest(cmd); } finally { _inProgress.decrementAndGet();
@Override protected void runInContext() { try { if (s_logger.isDebugEnabled()) { s_logger.debug("Simulating start for resource " + resource.getName() + " id " + id); } if (tapLoadingAgents(id, TapAgentsAction.Add)) { try { final AgentAttache agentattache = findAttache(id); if (agentattache == null) { s_logger.debug("Creating agent for host " + id); _resourceMgr.createHostAndAgent(id, resource, details, false, null, false); s_logger.debug("Completed creating agent for host " + id); } else { s_logger.debug("Agent already created in another thread for host " + id + ", ignore this"); } } finally { tapLoadingAgents(id, TapAgentsAction.Del); } } else { s_logger.debug("Agent creation already getting processed in another thread for host " + id + ", ignore this"); } } catch (final Exception e) { s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e); } } }
PingCommand cmd = resource.getCurrentStatus(_id); int retried = 0; while (cmd == null && ++retried <= _HostPingRetryCount.value()) { Thread.sleep(1000*_HostPingRetryTimer.value()); cmd = resource.getCurrentStatus(_id);
public void sendStartup(final Link link) { final StartupCommand[] startup = _resource.initialize(); if (startup != null) { final String msHostList = _shell.getPersistentProperty(null, "host"); final Command[] commands = new Command[startup.length]; for (int i = 0; i < startup.length; i++) { setupStartupCommand(startup[i]); startup[i].setMSHostList(msHostList); commands[i] = startup[i]; } final Request request = new Request(_id != null ? _id : -1, -1, commands, false, false); request.setSequence(getNextSequence()); if (s_logger.isDebugEnabled()) { s_logger.debug("Sending Startup: " + request.toString()); } lockStartupTask(link); try { link.send(request.toBytes()); } catch (final ClosedChannelException e) { s_logger.warn("Unable to send reques: " + request.toString()); } } }
cmds = resource.initialize(); if (cmds == null) { s_logger.info("Unable to fully initialize the agent because no StartupCommands are returned"); if (hostExists) { if (cmds != null) { resource.disconnected(); resource.disconnected();
ServerResource resource = new NetScalerControlCenterResource(); try { resource.configure(hostName, hostDetails); return Transaction.execute(new TransactionCallback<NetScalerControlCenterVO>() { @Override
@Override public Answer sendMessage(Command cmd) { if ((cmd instanceof CopyCommand) || (cmd instanceof DownloadCommand)) { return resource.executeRequest(cmd); } // TODO Auto-generated method stub return new Answer(cmd, false, "unsupported command:" + cmd.toString()); }
cancelTasks(); _resource.disconnected();
odlController.configure(hostParams.get("name"), hostdetails); final Host host = resourceManager.addHost(zoneId, odlController, Host.Type.L2Networking, hostParams); if (host != null) {
_resource.executeRequest(new PostCertificateRenewalCommand());
resource.configure(guid, hostDetails); } catch (ConfigurationException e) { throw new CloudRuntimeException(e.getMessage());