Examples of ClientCommandSender


Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

        try {
            if (args.length != 2) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
            } else {
                String subcommand = args[1];
                ClientCommandSender sender = agent.getClientCommandSender();

                if (sender != null) {
                    if (subcommand.equals(MSG.getMsg(AgentI18NResourceKeys.SENDER_START))) {
                        out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_STARTING));
                        sender.startSending();
                    } else if (subcommand.equals(MSG.getMsg(AgentI18NResourceKeys.SENDER_STOP))) {
                        out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_STOPPING));
                        sender.stopSending(true);
                    } else if (subcommand.equals(MSG.getMsg(AgentI18NResourceKeys.SENDER_METRICS))) {
                        ClientCommandSenderMetrics metrics = sender.getMetrics();

                        out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_METRICS_OUTPUT, metrics));
                    } else if (!subcommand.equals(MSG.getMsg(AgentI18NResourceKeys.SENDER_STATUS))) {
                        out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
                    }

                    if (sender.isSending()) {
                        out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_IS_SENDING));
                    } else {
                        out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_IS_NOT_SENDING));
                    }
                    out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_SERVER_ENDPOINT, sender.getRemoteCommunicator()
                        .getRemoteEndpoint()));
                } else {
                    out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_AGENT_NOT_STARTED));
                    AgentConfiguration agent_config = agent.getConfiguration();
                    out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_SERVER_ENDPOINT_CONFIG, agent_config
View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

                // Note that if the agent is not sending or the failover list doesn't have any servers,
                // then we skip this time and wait some more.
                // However, it the agent is sending and we have a failover list, then we need to check
                // to see if the server we are currently talking to is the same as primary server, listed
                // at the top of the failover list. If not the same, we ask the agent to switch to that server.
                ClientCommandSender sender = this.agent.getClientCommandSender();
                if (sender.isSending()) {
                    FailoverListComposite failoverList = this.agent.downloadServerFailoverList(); // ask the server for a new one

                    // if the failover list doesn't have any servers, skip our poll and wait some more
                    if (failoverList.size() > 0) {
                        AgentConfiguration config = this.agent.getConfiguration();
                        String transport = config.getServerTransport();
                        String transportParams = config.getServerTransportParams();
                        String currentServerAddress = config.getServerBindAddress();
                        int currentServerPort = config.getServerBindPort();

                        ServerEntry primary = failoverList.get(0); // get the top of the list, aka primary server
                        String primaryAddress = primary.address;
                        int primaryPort = (SecurityUtil.isTransportSecure(transport)) ? primary.securePort
                            : primary.port;

                        if (!primaryAddress.equals(currentServerAddress) || primaryPort != currentServerPort) {
                            LOG.info(AgentI18NResourceKeys.NOT_TALKING_TO_PRIMARY_SERVER, primaryAddress, primaryPort,
                                currentServerAddress, currentServerPort);
                            // create our own comm so we ping in an isolated client - don't reuse the sender's comm for this
                            RemoteCommunicator comm = this.agent.createServerRemoteCommunicator(transport,
                                primaryAddress, primaryPort, transportParams);
                            if (ping(comm)) {
                                LOG.info(AgentI18NResourceKeys.PRIMARY_SERVER_UP, primaryAddress, primaryPort);
                                failoverList.resetIndex(); // so the failover method call starts at the top
                                this.agent.failoverToNewServer(sender.getRemoteCommunicator()); // note that we make sure we pass in the sender's comm
                            } else {
                                LOG.info(AgentI18NResourceKeys.PRIMARY_SERVER_STILL_DOWN, primaryAddress, primaryPort);
                            }
                        }
                    }
View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

    public boolean execute(AgentMain agent, String[] args) {
        Command command = new IdentifyCommand();
        PrintWriter out = agent.getOut();

        try {
            ClientCommandSender sender = agent.getClientCommandSender();

            if (!agent.isStarted() || sender == null) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.IDENTIFY_NOT_SENDING));
            } else if (args.length <= 1) {
                // the user didn't specify a locator URI, by default, we'll send the command to our configured server
                out.println(MSG.getMsg(AgentI18NResourceKeys.IDENTIFY_ASK_SERVER_FOR_ID));
                CommandResponse response = sender.sendSynch(command);
                out.println(response);

                // let the server know about the time of the server
                if (response instanceof IdentifyCommandResponse && response.isSuccessful()) {
                    long serverTime = ((IdentifyCommandResponse) response).getIdentification().getTimestamp();
                    agent.serverClockNotification(serverTime);
                }
            } else if (args.length > 2) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
            } else {
                ServerEndpoint serverEndpoint = AgentUtils.getServerEndpoint(agent.getConfiguration(), args[1]);

                // use the generic client utility to issue the command
                RemoteCommunicator rc = agent.createServerRemoteCommunicator(serverEndpoint.transport,
                    serverEndpoint.namePort.address, serverEndpoint.namePort.port, serverEndpoint.transportParams);
                GenericCommandClient client = new GenericCommandClient(rc);

                out.println(MSG.getMsg(AgentI18NResourceKeys.IDENTIFY_ASK_REMOTE_SERVER_FOR_ID, args[1]));
                sender.preprocessCommand(command);
                CommandResponse response = client.invoke(command);

                client.disconnectRemoteCommunicator();

                out.println(response);
View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

     *
     * @return the server failover list that is now in effect
     */
    public FailoverListComposite downloadServerFailoverList() {
        try {
            ClientCommandSender sender = getClientCommandSender();
            if (sender != null) {
                String agent_name = this.getConfiguration().getAgentName();
                ClientRemotePojoFactory factory = sender.getClientRemotePojoFactory();
                CoreServerService pojo = factory.getRemotePojo(CoreServerService.class);
                FailoverListComposite list = pojo.getFailoverList(agent_name);
                if (list == null) {
                    list = new FailoverListComposite(new ArrayList<ServerEntry>());
                }
View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

                boolean hide_loopback_warning = Boolean.getBoolean("rhq.hide-agent-localhost-warning");
                boolean hide_failover_list_warning = false;

                while (retry) {
                    try {
                        ClientCommandSender sender = getClientCommandSender();

                        if ((sender == null) || Thread.currentThread().isInterrupted()) {
                            LOG.debug(AgentI18NResourceKeys.AGENT_REGISTRATION_ABORTED);
                            retry = false;
                        } else {
                            String token = getAgentSecurityToken();
                            ClientRemotePojoFactory pojo_factory = sender.getClientRemotePojoFactory();
                            CoreServerService remote_pojo = pojo_factory.getRemotePojo(CoreServerService.class);
                            AgentConfiguration agent_config = getConfiguration();
                            ServiceContainerConfiguration server_config = agent_config.getServiceContainerPreferences();
                            String agent_name = agent_config.getAgentName();
                            String address = server_config.getConnectorBindAddress();
                            int port = server_config.getConnectorBindPort();
                            String remote_endpoint = server_config.getConnectorRemoteEndpoint();
                            AgentVersion agentVersion = getAgentVersion();
                            String installId = System.getProperty(AgentRegistrationRequest.SYSPROP_INSTALL_ID);
                            String installLocation = getAgentHomeDirectory();
                            if (installLocation != null && installLocation.trim().length() == 0) {
                                installLocation = null; // tells the server we don't know it
                            }
                            AgentRegistrationRequest request = new AgentRegistrationRequest(agent_name, address, port,
                                remote_endpoint, regenerate_token, token, agentVersion, installId, installLocation);

                            Thread.sleep(retry_interval);

                            if (sender.isSending()) {
                                LOG.debug(AgentI18NResourceKeys.AGENT_REGISTRATION_ATTEMPT, request);

                                if (!hide_loopback_warning) {
                                    if (remote_endpoint.contains("localhost") || remote_endpoint.contains("127.0.0.")) {
                                        String msg_id = AgentI18NResourceKeys.REGISTERING_WITH_LOOPBACK;
                                        LOG.warn(msg_id, remote_endpoint);
                                        getOut().println(MSG.getMsg(msg_id, remote_endpoint));
                                        getOut().println();
                                        hide_loopback_warning = true; // don't bother to tell the user more than once
                                    }
                                }

                                // delete any old token so request is unauthenticated to get server to accept it
                                agent_config.setAgentSecurityToken(null);
                                m_commServices.addCustomData(
                                    SecurityTokenCommandAuthenticator.CMDCONFIG_PROP_SECURITY_TOKEN, null);

                                FailoverListComposite failover_list = null;
                                try {
                                    AgentRegistrationResults results = remote_pojo.registerAgent(request);
                                    failover_list = results.getFailoverList();
                                    token = results.getAgentToken(); // make sure our finally block gets this - BZ 963982

                                    // Try to do a simple connect to each server in the failover list
                                    // If only some of the servers are unreachable, just keep going;
                                    //    the agent will eventually switchover to one of the live servers.
                                    // But if all servers in the list are unreachable, we need to keep retrying hoping
                                    // someone fixes the servers' public endpoints so the agent can reach one or more of them.
                                    boolean test_failover_list = m_configuration.isTestFailoverListAtStartupEnabled();
                                    if (test_failover_list) {
                                        List<String> failed = testFailoverList(failover_list);
                                        if (failed.size() > 0) {
                                            if (failed.size() == failover_list.size()) {
                                                retry = true;
                                                retry_interval = 30000L;
                                                if (!hide_failover_list_warning) {
                                                    String msg_id = AgentI18NResourceKeys.FAILOVER_LIST_CHECK_FAILED;
                                                    LOG.warn(msg_id, failed.size(), failed.toString());
                                                    getOut().println(
                                                        MSG.getMsg(msg_id, failed.size(), failed.toString()));
                                                    getOut().println();
                                                    hide_failover_list_warning = true; // don't bother logging more than once
                                                }
                                                continue; // immediately go back and start the retry
                                            }
                                        }
                                    } else {
                                        LOG.info(AgentI18NResourceKeys.TEST_FAILOVER_LIST_AT_STARTUP_DISABLED);
                                    }

                                    m_registration = results;
                                    got_registered = true;
                                    retry = false;
                                    LOG.info(AgentI18NResourceKeys.AGENT_REGISTRATION_RESULTS, results);
                                } finally {
                                    // stores the new one if successful; restores the old one if we failed for some reason to register
                                    // Note that we don't retry even if storing the token fails since this kind
                                    // of failure is probably not recoverable even if we try again.
                                    agent_config.setAgentSecurityToken(token);
                                    m_commServices.addCustomData(
                                        SecurityTokenCommandAuthenticator.CMDCONFIG_PROP_SECURITY_TOKEN, token);

                                    LOG.debug(AgentI18NResourceKeys.NEW_SECURITY_TOKEN, token);
                                }

                                storeServerFailoverList(failover_list);
                                m_serverFailoverList = failover_list;

                                // switch away from the registration server and point this agent to the top of the list
                                // - this is our primary server that we should connect to
                                // note that if we are already pointing to the one at the head of the failover list,
                                // we don't have to failover to another server; the current one is the one we already want
                                if (failover_list.hasNext()) {
                                    String currentAddress = agent_config.getServerBindAddress();
                                    int currentPort = agent_config.getServerBindPort();
                                    String currentTransport = agent_config.getServerTransport();
                                    ServerEntry nextServer = failover_list.peek();

                                    if (currentAddress.equals(nextServer.address)
                                        && currentPort == (SecurityUtil.isTransportSecure(currentTransport) ? nextServer.securePort
                                            : nextServer.port)) {
                                        // we are already pointing to the primary server, so all we have to do is
                                        // call next to move the index to the next in the list for when we have to failover in the future
                                        nextServer = failover_list.next();

                                        // [mazz] I don't think we need to do this here anymore - with the addition of
                                        // the remote communicator's initialize callback, this connect request
                                        // will be made the next time a command is sent by the sender
                                        //sendConnectRequestToServer(sender.getRemoteCommunicator(), false);
                                    } else {
                                        failoverToNewServer(sender.getRemoteCommunicator());
                                    }
                                }
                            }
                        }
                    } catch (AgentNotSupportedException anse) {
View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

            public boolean stoppedSending(ClientCommandSender sender) {
                return true; // no-op but keep listening
            }
        };

        ClientCommandSender sender_to_server = getClientCommandSender();

        boolean zero = false;
        if (sender_to_server != null) {
            LOG.debug(AgentI18NResourceKeys.WAITING_FOR_SERVER, wait_ms);
            sender_to_server.addStateListener(listener, true);
            try {
                zero = latch.await(wait_ms, TimeUnit.MILLISECONDS);
                // if this agent is updating, break the loop immediately by throwing exception
                if (AgentUpdateThread.isUpdatingNow()) {
                    throw new AgentNotSupportedException();
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            } finally {
                sender_to_server.removeStateListener(listener);
            }
        } else {
            LOG.debug(AgentI18NResourceKeys.CANNOT_WAIT_FOR_SERVER);
        }
        return zero;
View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

    /**
     * This notifies the server that this agent is going down. This is called when the agent is shutting down.
     */
    private void notifyServerOfShutdown() {
        try {
            ClientCommandSender sender = getClientCommandSender();

            if (sender.isSending()) {
                LOG.debug(AgentI18NResourceKeys.NOTIFYING_SERVER_OF_SHUTDOWN);

                String agent_name = getConfiguration().getAgentName();
                ClientRemotePojoFactory pojo_factory = sender.getClientRemotePojoFactory();
                pojo_factory.setSendThrottled(false); // send it immediately, avoid any throttling
                pojo_factory.setTimeout(10000L); // try to be quick about it, if it can't send immediately, fail fast
                CoreServerService remote_pojo = pojo_factory.getRemotePojo(CoreServerService.class);

                remote_pojo.agentIsShuttingDown(agent_name);
View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

     */
    private ClientCommandSender createClientCommandSender() throws Exception {
        RemoteCommunicator remote_comm = createServerRemoteCommunicator(null, true, true);
        ClientCommandSenderConfiguration config = m_configuration.getClientCommandSenderConfiguration();

        ClientCommandSender client_sender = new ClientCommandSender(remote_comm, config, m_previouslyQueueCommands);

        for (CommandPreprocessor preproc : client_sender.getCommandPreprocessors()) {
            if (preproc instanceof SecurityTokenCommandPreprocessor) {
                ((SecurityTokenCommandPreprocessor) preproc).setAgentConfiguration(m_configuration);
            }
        }

View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

     */
    private String getDefaultPrompt() {
        String prompt;

        if (LOG.isDebugEnabled()) {
            ClientCommandSender sender = m_clientSender;
            if ((sender != null) && isStarted()) {
                prompt = (sender.isSending()) ? PROMPT_SENDING : PROMPT_STARTED;
            } else {
                prompt = PROMPT_SHUTDOWN;
            }
        } else {
            prompt = PROMPT_TINY;
View Full Code Here

Examples of org.rhq.enterprise.communications.command.client.ClientCommandSender

            for (ServiceContainerSenderCreationListener listener : m_senderCreationListeners) {
                listener.preCreate(this, remote_comm, client_config);
            }

            ClientCommandSender sender = new ClientCommandSender(remote_comm, client_config);

            for (ServiceContainerSenderCreationListener listener : m_senderCreationListeners) {
                listener.postCreate(this, sender);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.