Examples of NetworkUsageAnswer


Examples of com.cloud.agent.api.NetworkUsageAnswer

                                final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(),
                                        forVpc, routerNic.getIp4Address());
                                String routerType = router.getType().toString();
                                UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(),
                                        router.getDataCenterIdToDeployIn(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
                                NetworkUsageAnswer answer = null;
                                try {
                                    answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd);
                                } catch (Exception e) {
                                    s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId(), e);
                                    continue;
                                }

                                if (answer != null) {
                                    if (!answer.getResult()) {
                                        s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId() + "; details: " + answer.getDetails());
                                        continue;
                                    }
                                    Transaction txn = Transaction.open(Transaction.CLOUD_DB);
                                    try {
                                        if ((answer.getBytesReceived() == 0) && (answer.getBytesSent() == 0)) {
                                            s_logger.debug("Recieved and Sent bytes are both 0. Not updating user_statistics");
                                            continue;
                                        }
                                        txn.start();
                                        UserStatisticsVO stats = _statsDao.lock(router.getAccountId(),
                                                router.getDataCenterIdToDeployIn(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
                                        if (stats == null) {
                                            s_logger.warn("unable to find stats for account: " + router.getAccountId());
                                            continue;
                                        }

                                        if (previousStats != null
                                                && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived())
                                                || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))) {
                                            s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " +
                                                    "Ignoring current answer. Router: " + answer.getRouterName() + " Rcvd: " +
                                                    answer.getBytesReceived() + "Sent: " + answer.getBytesSent());
                                            continue;
                                        }

                                        if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) {
                                            if (s_logger.isDebugEnabled()) {
                                                s_logger.debug("Received # of bytes that's less than the last one.  " +
                                                        "Assuming something went wrong and persisting it. Router: " +
                                                        answer.getRouterName() + " Reported: " + answer.getBytesReceived()
                                                        + " Stored: " + stats.getCurrentBytesReceived());
                                            }
                                            stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                                        }
                                        stats.setCurrentBytesReceived(answer.getBytesReceived());
                                        if (stats.getCurrentBytesSent() > answer.getBytesSent()) {
                                            if (s_logger.isDebugEnabled()) {
                                                s_logger.debug("Received # of bytes that's less than the last one.  " +
                                                        "Assuming something went wrong and persisting it. Router: " +
                                                        answer.getRouterName() + " Reported: " + answer.getBytesSent()
                                                        + " Stored: " + stats.getCurrentBytesSent());
                                            }
                                            stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                                        }
                                        stats.setCurrentBytesSent(answer.getBytesSent());
                                        _statsDao.update(stats.getId(), stats);
                                        txn.commit();
                                    } catch (Exception e) {
                                        txn.rollback();
                                        s_logger.warn("Unable to update user statistics for account: " + router.getAccountId()
                                                + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent());
                                    } finally {
                                        txn.close();
                                    }
                                }
                            }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

            } else if (option.equals("vpn")) {
                args += "-n";
            } else if (option.equals("remove")) {
                args += "-d";
            } else {
                return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
            }

            String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
            if (option.equals("get") || option.equals("vpn")) {
                long[] stats = new long[2];
                if (result != null) {
                    String[] splitResult = result.split(":");
                    int i = 0;
                    while (i < splitResult.length - 1) {
                        stats[0] += (new Long(splitResult[i++])).longValue();
                        stats[1] += (new Long(splitResult[i++])).longValue();
                    }
                    return new NetworkUsageAnswer(cmd, "success", stats[0], stats[1]);
                }
            }
            if (result == null || result.isEmpty()) {
                throw new Exception(" vpc network usage plugin call failed ");
            }
            return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
        } catch (Exception ex) {
            s_logger.warn("Failed to get network usage stats due to ", ex);
            return new NetworkUsageAnswer(cmd, ex);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

        }
        try {
            Connection conn = getConnection();
            if(cmd.getOption()!=null && cmd.getOption().equals("create") ){
                String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
                NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
                return answer;
            }
            long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
            NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
            return answer;
        } catch (Exception ex) {
            s_logger.warn("Failed to get network usage stats due to ", ex);
            return new NetworkUsageAnswer(cmd, ex);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

                    boolean forVpc = router.getVpcId() != null;
                    final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(),
                            forVpc, routerNic.getIp4Address());
                    UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(),
                            router.getDataCenterIdToDeployIn(), network.getId(), null, router.getId(), router.getType().toString());
                    NetworkUsageAnswer answer = null;
                    try {
                        answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd);
                    } catch (Exception e) {
                        s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId(), e);
                        continue;
                    }

                    if (answer != null) {
                        if (!answer.getResult()) {
                            s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId() + "; details: " + answer.getDetails());
                            continue;
                        }
                        Transaction txn = Transaction.open(Transaction.CLOUD_DB);
                        try {
                            if ((answer.getBytesReceived() == 0) && (answer.getBytesSent() == 0)) {
                                s_logger.debug("Recieved and Sent bytes are both 0. Not updating user_statistics");
                                continue;
                            }
                            txn.start();
                            UserStatisticsVO stats = _statsDao.lock(router.getAccountId(),
                                    router.getDataCenterIdToDeployIn(), network.getId(), null, router.getId(), router.getType().toString());
                            if (stats == null) {
                                s_logger.warn("unable to find stats for account: " + router.getAccountId());
                                continue;
                            }

                            if(previousStats != null
                                    && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived())
                                            || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){
                                s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " +
                                        "Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " +
                                        answer.getBytesReceived()+ "Sent: " +answer.getBytesSent());
                                continue;
                            }

                            if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) {
                                if (s_logger.isDebugEnabled()) {
                                    s_logger.debug("Received # of bytes that's less than the last one.  " +
                                            "Assuming something went wrong and persisting it. Router: " +
                                            answer.getRouterName()+" Reported: " + answer.getBytesReceived()
                                            + " Stored: " + stats.getCurrentBytesReceived());
                                }
                                stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                            }
                            stats.setCurrentBytesReceived(answer.getBytesReceived());
                            if (stats.getCurrentBytesSent() > answer.getBytesSent()) {
                                if (s_logger.isDebugEnabled()) {
                                    s_logger.debug("Received # of bytes that's less than the last one.  " +
                                            "Assuming something went wrong and persisting it. Router: " +
                                            answer.getRouterName()+" Reported: " + answer.getBytesSent()
                                            + " Stored: " + stats.getCurrentBytesSent());
                                }
                                stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                            }
                            stats.setCurrentBytesSent(answer.getBytesSent());
                            _statsDao.update(stats.getId(), stats);
                            txn.commit();
                        } catch (Exception e) {
                            txn.rollback();
                            s_logger.warn("Unable to update user statistics for account: " + router.getAccountId()
                                    + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent());
                        } finally {
                            txn.close();
                        }
                    }
                }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

    }

    private Answer execute(NetworkUsageCommand cmd) {
        if (cmd.getOption() != null && cmd.getOption().equals("create")) {
            String result = networkUsage(cmd.getPrivateIP(), "create", null);
            NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L,
                    0L);
            return answer;
        }
        long[] stats = getNetworkStats(cmd.getPrivateIP());
        NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0],
                stats[1]);
        return answer;
    }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

    protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {
        try {
            Connection conn = getConnection();
            if (cmd.getOption() != null && cmd.getOption().equals("create")) {
                String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
                NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
                return answer;
            }
            long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
            NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
            return answer;
        } catch (Exception ex) {
            s_logger.warn("Failed to get network usage stats due to ", ex);
            return new NetworkUsageAnswer(cmd, ex);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

            } else if (option.equals("vpn")) {
                args += "-n";
            } else if (option.equals("remove")) {
                args += "-d";
            } else {
                return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
            }

            ExecutionResult result = executeInVR(cmd.getPrivateIP(), "vpc_netusage.sh", args);
            String detail = result.getDetails();
            if (!result.isSuccess()) {
                throw new Exception(" vpc network usage plugin call failed ");
            }
            if (option.equals("get") || option.equals("vpn")) {
                long[] stats = new long[2];
                if (detail != null) {
                    String[] splitResult = detail.split(":");
                    int i = 0;
                    while (i < splitResult.length - 1) {
                        stats[0] += (new Long(splitResult[i++])).longValue();
                        stats[1] += (new Long(splitResult[i++])).longValue();
                    }
                    return new NetworkUsageAnswer(cmd, "success", stats[0], stats[1]);
                }
            }
            return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
        } catch (Exception ex) {
            s_logger.warn("Failed to get network usage stats due to ", ex);
            return new NetworkUsageAnswer(cmd, ex);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

        }
        try {
            Connection conn = getConnection();
            if (cmd.getOption() != null && cmd.getOption().equals("create")) {
                String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
                NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
                return answer;
            }
            long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
            NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
            return answer;
        } catch (Exception ex) {
            s_logger.warn("Failed to get network usage stats due to ", ex);
            return new NetworkUsageAnswer(cmd, ex);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

        return new SetFirewallRulesAnswer(cmd, true, results);
    }

    @Override
    public NetworkUsageAnswer getNetworkUsage(NetworkUsageCommand cmd) {
        return new NetworkUsageAnswer(cmd, null, 100L, 100L);
    }
View Full Code Here

Examples of com.cloud.agent.api.NetworkUsageAnswer

    private Answer execute(NetworkUsageCommand cmd) {
        if (cmd.isForVpc()) {
            if (cmd.getOption() != null && cmd.getOption().equals("create")) {
                String result = VPCNetworkUsage(cmd.getPrivateIP(), cmd.getGatewayIP(), "create", cmd.getVpcCIDR());
                NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
                return answer;
            } else if (cmd.getOption() != null && (cmd.getOption().equals("get") || cmd.getOption().equals("vpn"))) {
                long[] stats = getVPCNetworkStats(cmd.getPrivateIP(), cmd.getGatewayIP(), cmd.getOption());
                NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
                return answer;
            } else {
                String result = VPCNetworkUsage(cmd.getPrivateIP(), cmd.getGatewayIP(), cmd.getOption(), cmd.getVpcCIDR());
                NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
                return answer;
            }
        } else {
            if (cmd.getOption() != null && cmd.getOption().equals("create")) {
                String result = networkUsage(cmd.getPrivateIP(), "create", null);
                NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
                return answer;
            }
            long[] stats = getNetworkStats(cmd.getPrivateIP());
            NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
            return answer;
        }
    }
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.