mirror of https://github.com/apache/cloudstack.git
152 lines
4.6 KiB
Java
152 lines
4.6 KiB
Java
// Licensed to the Apache Software Foundation (ASF) under one
|
|
// or more contributor license agreements. See the NOTICE file
|
|
// distributed with this work for additional information
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
// to you under the Apache License, Version 2.0 (the
|
|
// "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
package com.cloud.resource;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.ejb.Local;
|
|
import javax.naming.ConfigurationException;
|
|
|
|
import com.cloud.agent.AgentManager;
|
|
import com.cloud.agent.Listener;
|
|
import com.cloud.agent.api.AgentControlAnswer;
|
|
import com.cloud.agent.api.AgentControlCommand;
|
|
import com.cloud.agent.api.Answer;
|
|
import com.cloud.agent.api.Command;
|
|
import com.cloud.agent.api.StartupCommand;
|
|
import com.cloud.agent.api.StartupSecondaryStorageCommand;
|
|
import com.cloud.agent.manager.MockStorageManager;
|
|
import com.cloud.exception.ConnectionException;
|
|
import com.cloud.host.HostVO;
|
|
import com.cloud.host.Status;
|
|
import com.cloud.storage.SnapshotVO;
|
|
import com.cloud.storage.dao.SnapshotDao;
|
|
import com.cloud.storage.secondary.SecondaryStorageDiscoverer;
|
|
import com.cloud.utils.component.Inject;
|
|
import com.cloud.utils.exception.CloudRuntimeException;
|
|
@Local(value=Discoverer.class)
|
|
public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer implements ResourceStateAdapter, Listener {
|
|
@Inject MockStorageManager _mockStorageMgr = null;
|
|
@Inject AgentManager _agentMgr;
|
|
@Inject ResourceManager _resourceMgr;
|
|
@Inject SnapshotDao _snapshotDao;
|
|
|
|
@Override
|
|
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
|
_agentMgr.registerForHostEvents(this, true, false, false);
|
|
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
|
|
return super.configure(name, params);
|
|
}
|
|
|
|
@Override
|
|
public void postDiscovery(List<HostVO> hosts, long msId) {
|
|
super.postDiscovery(hosts, msId);
|
|
for (HostVO host: hosts) {
|
|
_mockStorageMgr.preinstallTemplates(host.getStorageUrl(), host.getDataCenterId());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public HostVO createHostVOForConnectedAgent(HostVO host,
|
|
StartupCommand[] cmd) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public HostVO createHostVOForDirectConnectAgent(HostVO host,
|
|
StartupCommand[] startup, ServerResource resource,
|
|
Map<String, String> details, List<String> hostTags) {
|
|
//for detecting SSVM dispatch
|
|
StartupCommand firstCmd = startup[0];
|
|
if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
|
|
return null;
|
|
}
|
|
|
|
host.setType(com.cloud.host.Host.Type.SecondaryStorageVM);
|
|
return host;
|
|
}
|
|
|
|
@Override
|
|
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
|
|
boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
|
long hostId = host.getId();
|
|
List<SnapshotVO> snapshots = _snapshotDao.listByHostId(hostId);
|
|
if (snapshots != null && !snapshots.isEmpty()) {
|
|
throw new CloudRuntimeException("Cannot delete this secondary storage because there are still snapshots on it ");
|
|
}
|
|
_vmTemplateHostDao.deleteByHost(hostId);
|
|
host.setGuid(null);
|
|
_hostDao.update(hostId, host);
|
|
_hostDao.remove(hostId);
|
|
return new DeleteHostAnswer(true);
|
|
}
|
|
|
|
@Override
|
|
public boolean start() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean stop() {
|
|
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getTimeout() {
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public boolean isRecurring() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean processCommands(long agentId, long seq, Command[] commands) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void processConnect(HostVO host, StartupCommand cmd,
|
|
boolean forRebalance) throws ConnectionException {
|
|
|
|
}
|
|
|
|
@Override
|
|
public AgentControlAnswer processControlCommand(long agentId,
|
|
AgentControlCommand cmd) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public boolean processDisconnect(long agentId, Status state) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean processTimeout(long agentId, long seq) {
|
|
return false;
|
|
}
|
|
}
|