Search in sources :

Example 1 with SecStorageSetupAnswer

use of com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

private Answer execute(final SecStorageSetupCommand cmd) {
    if (!this._inSystemVM) {
        return new Answer(cmd, true, null);
    }
    Answer answer = null;
    final DataStoreTO dStore = cmd.getDataStore();
    if (dStore instanceof NfsTO) {
        final String secUrl = cmd.getSecUrl();
        try {
            final URI uri = new URI(secUrl);
            final String nfsHostIp = getUriHostIp(uri);
            final String dir = mountUri(uri);
            configCerts(cmd.getCerts());
            this.nfsIps.add(nfsHostIp);
            answer = new SecStorageSetupAnswer(dir);
        } catch (final Exception e) {
            final String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
            s_logger.error(msg);
            answer = new Answer(cmd, false, msg);
        }
    } else {
        answer = new Answer(cmd, true, null);
    }
    savePostUploadPSK(cmd.getPostUploadKey());
    startPostUploadServer();
    return answer;
}
Also used : ListTemplateAnswer(com.cloud.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 2 with SecStorageSetupAnswer

use of com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer in project cosmic by MissionCriticalCloud.

the class SecondaryStorageManagerImpl method generateSetupCommand.

@Override
public boolean generateSetupCommand(final Long ssHostId) {
    final HostVO cssHost = this._hostDao.findById(ssHostId);
    final Long zoneId = cssHost.getDataCenterId();
    if (cssHost.getType() == HostType.SecondaryStorageVM) {
        final SecondaryStorageVmVO secStorageVm = this._secStorageVmDao.findByInstanceName(cssHost.getName());
        if (secStorageVm == null) {
            logger.warn("secondary storage VM " + cssHost.getName() + " doesn't exist");
            return false;
        }
        final List<DataStore> ssStores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
        for (final DataStore ssStore : ssStores) {
            if (!(ssStore.getTO() instanceof NfsTO)) {
                // only do this for Nfs
                continue;
            }
            final String secUrl = ssStore.getUri();
            final SecStorageSetupCommand setupCmd;
            if (!this._useSSlCopy) {
                setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
            } else {
                final Certificates certs = this._keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
                setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
            }
            // template/volume file upload key
            final String postUploadKey = this._configDao.getValue(Config.SSVMPSK.key());
            setupCmd.setPostUploadKey(postUploadKey);
            final Answer answer = this._agentMgr.easySend(ssHostId, setupCmd);
            if (answer != null && answer.getResult()) {
                final SecStorageSetupAnswer an = (SecStorageSetupAnswer) answer;
                if (an.get_dir() != null) {
                    // update the parent path in image_store table for this image store
                    final ImageStoreVO svo = this._imageStoreDao.findById(ssStore.getId());
                    svo.setParent(an.get_dir());
                    this._imageStoreDao.update(ssStore.getId(), svo);
                }
                logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
            } else {
                logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
                return false;
            }
        }
    }
    return true;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) Certificates(com.cloud.legacymodel.auth.Certificates) SecStorageSetupCommand(com.cloud.legacymodel.communication.command.SecStorageSetupCommand) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) NfsTO(com.cloud.legacymodel.to.NfsTO) HostVO(com.cloud.host.HostVO) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) CheckSshAnswer(com.cloud.legacymodel.communication.answer.CheckSshAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)2 SecStorageSetupAnswer (com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer)2 NfsTO (com.cloud.legacymodel.to.NfsTO)2 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)1 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)1 HostVO (com.cloud.host.HostVO)1 Certificates (com.cloud.legacymodel.auth.Certificates)1 CheckHealthAnswer (com.cloud.legacymodel.communication.answer.CheckHealthAnswer)1 CheckSshAnswer (com.cloud.legacymodel.communication.answer.CheckSshAnswer)1 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)1 GetStorageStatsAnswer (com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer)1 ListTemplateAnswer (com.cloud.legacymodel.communication.answer.ListTemplateAnswer)1 ListVolumeAnswer (com.cloud.legacymodel.communication.answer.ListVolumeAnswer)1 ReadyAnswer (com.cloud.legacymodel.communication.answer.ReadyAnswer)1 UploadStatusAnswer (com.cloud.legacymodel.communication.answer.UploadStatusAnswer)1 SecStorageSetupCommand (com.cloud.legacymodel.communication.command.SecStorageSetupCommand)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)1 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)1 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)1