Search in sources :

Example 41 with StartupCommand

use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.

the class BareMetalDiscoverer method createHostVOForDirectConnectAgent.

@Override
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
    StartupCommand firstCmd = startup[0];
    if (!(firstCmd instanceof StartupRoutingCommand)) {
        return null;
    }
    StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
    if (ssCmd.getHypervisorType() != HypervisorType.BareMetal) {
        return null;
    }
    return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.BareMetal, details, hostTags);
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 42 with StartupCommand

use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.

the class HypervDirectConnectResource method requestStartupCommand.

// TODO: Is it valid to return NULL, or should we throw on error?
// Returns StartupCommand with fields revised with values known only to the
// host
public final Command[] requestStartupCommand(final Command[] cmd) {
    // Set HTTP POST destination URI
    // Using java.net.URI, see
    // http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URI.html
    URI agentUri = null;
    try {
        final String cmdName = StartupCommand.class.getName();
        agentUri = new URI("https", null, _agentIp, _port, "/api/HypervResource/" + cmdName, null, null);
    } catch (final URISyntaxException e) {
        // TODO add proper logging
        final String errMsg = "Could not generate URI for Hyper-V agent";
        s_logger.error(errMsg, e);
        return null;
    }
    final String incomingCmd = postHttpRequest(s_gson.toJson(cmd), agentUri);
    if (incomingCmd == null) {
        return null;
    }
    Command[] result = null;
    try {
        result = s_gson.fromJson(incomingCmd, Command[].class);
    } catch (final Exception ex) {
        final String errMsg = "Failed to deserialize Command[] " + incomingCmd;
        s_logger.error(errMsg, ex);
    }
    s_logger.debug("requestStartupCommand received response " + s_gson.toJson(result));
    if (result.length > 0) {
        return result;
    }
    return null;
}
Also used : CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) Site2SiteVpnCfgCommand(com.cloud.agent.api.routing.Site2SiteVpnCfgCommand) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) SetupGuestNetworkCommand(com.cloud.agent.api.SetupGuestNetworkCommand) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) ModifyVmNicConfigCommand(com.cloud.agent.api.ModifyVmNicConfigCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) SetStaticRouteCommand(com.cloud.agent.api.routing.SetStaticRouteCommand) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) VmDataCommand(com.cloud.agent.api.routing.VmDataCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) CreateIpAliasCommand(com.cloud.agent.api.routing.CreateIpAliasCommand) SetMonitorServiceCommand(com.cloud.agent.api.routing.SetMonitorServiceCommand) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) RemoteAccessVpnCfgCommand(com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand) Command(com.cloud.agent.api.Command) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) DeleteIpAliasCommand(com.cloud.agent.api.routing.DeleteIpAliasCommand) DhcpEntryCommand(com.cloud.agent.api.routing.DhcpEntryCommand) StartCommand(com.cloud.agent.api.StartCommand) GetVmConfigCommand(com.cloud.agent.api.GetVmConfigCommand) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) StartupCommand(com.cloud.agent.api.StartupCommand) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) SetFirewallRulesCommand(com.cloud.agent.api.routing.SetFirewallRulesCommand) IpAssocVpcCommand(com.cloud.agent.api.routing.IpAssocVpcCommand) SetNetworkACLCommand(com.cloud.agent.api.routing.SetNetworkACLCommand) VpnUsersCfgCommand(com.cloud.agent.api.routing.VpnUsersCfgCommand) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException)

Example 43 with StartupCommand

use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.

the class XenServerResourceNewBase method initialize.

@Override
public StartupCommand[] initialize() throws IllegalArgumentException {
    final StartupCommand[] cmds = super.initialize();
    final Connection conn = getConnection();
    Pool pool;
    try {
        pool = Pool.getByUuid(conn, _host.getPool());
        final Pool.Record poolr = pool.getRecord(conn);
        final Host.Record masterRecord = poolr.master.getRecord(conn);
        if (_host.getUuid().equals(masterRecord.uuid)) {
            _listener = new VmEventListener(true);
        //
        // TODO disable event listener for now. Wait until everything else is ready
        //
        // _listener.start();
        } else {
            _listener = new VmEventListener(false);
        }
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("Unable to determine who is the master", e);
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("Unable to determine who is the master", e);
    }
    return cmds;
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Pool(com.xensource.xenapi.Pool) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 44 with StartupCommand

use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.

the class DummyHostServerResource method initialize.

@Override
public StartupCommand[] initialize() {
    StartupRoutingCommand cmd = new StartupRoutingCommand();
    cmd.setCpus(1);
    cmd.setSpeed(1000L);
    cmd.setMemory(1000000L);
    cmd.setDom0MinMemory(256L);
    cmd.setCaps("hvm");
    cmd.setGuid(_guid);
    cmd.setDataCenter(_zone);
    cmd.setPod(_pod);
    cmd.setHypervisorType(HypervisorType.None);
    cmd.setAgentTag("vmops-simulator");
    cmd.setName(_url);
    cmd.setPrivateIpAddress(this.getHostPrivateIp());
    cmd.setPrivateMacAddress(this.getHostMacAddress().toString());
    cmd.setPrivateNetmask("255.255.0.0");
    cmd.setIqn("iqn:" + _url);
    cmd.setStorageIpAddress(getHostStoragePrivateIp());
    cmd.setStorageMacAddress(getHostStorageMacAddress().toString());
    cmd.setStorageIpAddressDeux(getHostStoragePrivateIp2());
    cmd.setStorageMacAddressDeux(getHostStorageMacAddress2().toString());
    cmd.setPublicIpAddress(getHostStoragePrivateIp());
    cmd.setPublicMacAddress(getHostStorageMacAddress().toString());
    cmd.setPublicNetmask("255.255.0.0");
    cmd.setVersion(DummyHostServerResource.class.getPackage().getImplementationVersion());
    return new StartupCommand[] { cmd };
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 45 with StartupCommand

use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.

the class ResourceManagerImpl method createHostAndAgentDeferred.

private Host createHostAndAgentDeferred(final ServerResource resource, final Map<String, String> details, final boolean old, final List<String> hostTags, final boolean forRebalance) {
    HostVO host = null;
    StartupCommand[] cmds = null;
    boolean hostExists = false;
    boolean deferAgentCreation = true;
    boolean created = false;
    try {
        cmds = resource.initialize();
        if (cmds == null) {
            s_logger.info("Unable to fully initialize the agent because no StartupCommands are returned");
            return null;
        }
        /* Generate a random version in a dev setup situation */
        if (this.getClass().getPackage().getImplementationVersion() == null) {
            for (final StartupCommand cmd : cmds) {
                if (cmd.getVersion() == null) {
                    cmd.setVersion(Long.toString(System.currentTimeMillis()));
                }
            }
        }
        if (s_logger.isDebugEnabled()) {
            new Request(-1l, -1l, cmds, true, false).logD("Startup request from directly connected host: ", true);
        }
        if (old) {
            final StartupCommand firstCmd = cmds[0];
            host = findHostByGuid(firstCmd.getGuid());
            if (host == null) {
                host = findHostByGuid(firstCmd.getGuidWithoutResource());
            }
            if (host != null && host.getRemoved() == null) {
                // host already
                // added, no
                // need to add
                // again
                s_logger.debug("Found the host " + host.getId() + " by guid: " + firstCmd.getGuid() + ", old host reconnected as new");
                // ensures that host status is left
                hostExists = true;
                // again
                return null;
            }
        }
        host = null;
        boolean newHost = false;
        final GlobalLock addHostLock = GlobalLock.getInternLock("AddHostLock");
        try {
            if (addHostLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
                // to safely determine first host in cluster in multi-MS scenario
                try {
                    // find out if the host we want to connect to is new (so we can send an event)
                    newHost = getNewHost(cmds) == null;
                    host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT);
                    if (host != null) {
                        // if first host in cluster no need to defer agent creation
                        deferAgentCreation = !isFirstHostInCluster(host);
                    }
                } finally {
                    addHostLock.unlock();
                }
            }
        } finally {
            addHostLock.releaseRef();
        }
        if (host != null) {
            if (!deferAgentCreation) {
                // if first host in cluster then
                created = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance, newHost);
                // reload
                host = _hostDao.findById(host.getId());
            } else {
                // reload
                host = _hostDao.findById(host.getId());
                // force host status to 'Alert' so that it is loaded for
                // connection during next scan task
                _agentMgr.agentStatusTransitTo(host, Status.Event.AgentDisconnected, _nodeId);
                // reload
                host = _hostDao.findById(host.getId());
                // so that scan task can pick it up
                host.setLastPinged(0);
                _hostDao.update(host.getId(), host);
            }
        }
    } catch (final Exception e) {
        s_logger.warn("Unable to connect due to ", e);
    } finally {
        if (hostExists) {
            if (cmds != null) {
                resource.disconnected();
            }
        } else {
            if (!deferAgentCreation && !created) {
                if (cmds != null) {
                    resource.disconnected();
                }
                markHostAsDisconnected(host, cmds);
            }
        }
    }
    return host;
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) GlobalLock(com.cloud.utils.db.GlobalLock) Request(com.cloud.agent.transport.Request) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) SshException(com.cloud.utils.ssh.SshException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Aggregations

StartupCommand (com.cloud.agent.api.StartupCommand)60 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)28 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 ConfigurationException (javax.naming.ConfigurationException)7 Command (com.cloud.agent.api.Command)6 StartupSecondaryStorageCommand (com.cloud.agent.api.StartupSecondaryStorageCommand)6 PingCommand (com.cloud.agent.api.PingCommand)5 HostVO (com.cloud.host.HostVO)5 URISyntaxException (java.net.URISyntaxException)5 Request (com.cloud.agent.transport.Request)4 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)3 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)3 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)3 StartCommand (com.cloud.agent.api.StartCommand)3 StartupProxyCommand (com.cloud.agent.api.StartupProxyCommand)3 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)3 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)2 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)2 CronCommand (com.cloud.agent.api.CronCommand)2