private void runAgentUpdate() throws RetryAfterException, InterruptedException { if (isInterrupted()) { throw new InterruptedException("Controller was interrupted, not running agent updates check..."); } logDebug("Checking for agent updates..."); long maxRetries = m_maxRetries.get(); boolean fixPackage = m_fixPackage.get(); UpdateInstaller updateInstaller = getUpdateInstaller(); try { updateInstaller.installUpdate(getAgentUpdateHandler(), fixPackage, maxRetries); } catch (IOException e) { logError("Agent update aborted due to Exception.", e); } }
private void runDeploymentUpdate() throws RetryAfterException, InterruptedException { if (isInterrupted()) { throw new InterruptedException("Controller was interrupted, not running deployment updates check..."); } logDebug("Checking for deployment updates..."); long maxRetries = m_maxRetries.get(); boolean fixPackage = m_fixPackage.get(); UpdateInstaller updateInstaller = getUpdateInstaller(); try { updateInstaller.installUpdate(getDeploymentHandler(), fixPackage, maxRetries); } catch (IOException e) { logError("Deployment update aborted due to Exception.", e); } }
private void runFeedback() throws RetryAfterException, InterruptedException { if (isInterrupted()) { throw new InterruptedException("Controller was interrupted, not running feedback synchronization..."); } Set<String> names = getFeedbackChannelNames(); logDebug("Synchronizing feedback channels: %s", names); for (String name : names) { FeedbackChannel channel = getFeedbackChannel(name); if (channel != null) { try { channel.sendFeedback(); logDebug("Feedback send succesfully for channel: %s", name); } catch (IOException e) { // Hopefully temporary problem due to remote IO or configuration. No cause to abort the sync so we // just log it as a warning. logWarning("Exception while sending feedback for channel: %s", e, name); } } } }
private FeedbackChannel getFeedbackChannel(String name) { try { return getFeedbackHandler().getChannel(name); } catch (IOException e) { // Probably a serious problem due to local IO related to feedback. No cause to abort the sync so we just log // it as an error. logError("Exception while looking up feedback channel %s", e, name); } return null; }
@Override protected void onInit() throws Exception { getEventsHandler().addListener(this); // The controller is started *after* all other components, causing it to miss the initial configuration-update // event, hence we need to get the configuration ourselves for the first time... ConfigurationHandler config = getConfigurationHandler(); m_updateStreaming.set(config.getBoolean(CONFIG_CONTROLLER_STREAMING, m_updateStreaming.get())); m_fixPackage.set(config.getBoolean(CONFIG_CONTROLLER_FIXPACKAGES, m_fixPackage.get())); m_interval.set(config.getLong(CONFIG_CONTROLLER_SYNCINTERVAL, m_interval.get())); m_syncDelay.set(config.getLong(CONFIG_CONTROLLER_SYNCDELAY, m_syncDelay.get())); m_maxRetries.set(config.getLong(CONFIG_CONTROLLER_RETRIES, m_maxRetries.get())); logDebug("Config initialized: update: %s, fixPkg: %s, syncDelay: %d, syncInterval: %d, maxRetries: %d", m_updateStreaming.get(), m_fixPackage.get(), m_syncDelay.get(), m_interval.get(), m_maxRetries.get()); }
protected void sendDeploymentInstallEvent(UpdateInfo updateInfo) { Map<String, String> eventProps = new HashMap<>(); eventProps.put("type", updateInfo.m_type); eventProps.put("name", getIdentificationHandler().getAgentId()); eventProps.put("fromVersion", updateInfo.m_from.toString()); eventProps.put("toVersion", updateInfo.m_to.toString()); eventProps.put("fixPackage", Boolean.toString(updateInfo.m_fixPackage)); getEventsHandler().postEvent(AGENT_INSTALLATION_START, eventProps); }
/** * Factory method for creating the agent controller. * * @param context * the bundle context to use, cannot be <code>null</code>. * @return a controller instance, never <code>null</code>. * @throws ClassNotFoundException * in case a custom controller class was defined, but this class could not be loaded; * @throws IllegalAccessException * in case a custom controller class was defined, but did not have a public default constructor; * @throws InstantiationException * in case a custom controller class was defined, but instantiation lead to an exception. */ private Object createAgentController(BundleContext context) throws ClassNotFoundException, InstantiationException, IllegalAccessException { String controllerName = context.getProperty(AgentConstants.CONFIG_CONTROLLER_CLASS); if (controllerName != null) { Class<?> controllerClass = context.getBundle().loadClass(controllerName); return controllerClass.newInstance(); } return new DefaultController(); }
@Override protected void onStop() throws Exception { EventsHandler eventsHandler = getEventsHandler(); if (eventsHandler != null) { eventsHandler.removeListener(this); } if (m_updateInstaller != null) { m_updateInstaller.reset(); m_updateInstaller = null; } }
private Set<String> getFeedbackChannelNames() { try { return getFeedbackHandler().getChannelNames(); } catch (IOException e) { // Probably a serious problem due to local IO related to feedback. No cause to abort the sync so we just log // it as an error. logError("Exception while looking up feedback channel names."); } return Collections.emptySet(); }
protected void sendDeploymentCompletedEvent(UpdateInfo updateInfo, boolean success, Throwable throwable) { Map<String, String> eventProps = new HashMap<>(); eventProps.put("type", updateInfo.m_type); eventProps.put("name", getIdentificationHandler().getAgentId()); eventProps.put("fromVersion", updateInfo.m_from.toString()); eventProps.put("toVersion", updateInfo.m_to.toString()); eventProps.put("fixPackage", Boolean.toString(updateInfo.m_fixPackage)); eventProps.put("successful", Boolean.toString(success)); if (throwable != null) { eventProps.put("exception", throwable.getMessage()); } getEventsHandler().postEvent(AGENT_INSTALLATION_COMPLETE, eventProps); }