mirror of https://github.com/apache/cloudstack.git
fix simulator
This commit is contained in:
parent
e731722263
commit
94aa67eae0
|
|
@ -41,11 +41,11 @@ public class AddSecondaryStorageCmd extends BaseCmd {
|
|||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, required=true, description="the URL for the secondary storage")
|
||||
private String url;
|
||||
protected String url;
|
||||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class,
|
||||
description="the Zone ID for the secondary storage")
|
||||
private Long zoneId;
|
||||
protected Long zoneId;
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@
|
|||
<bean id="SimulatorDiscoverer" class="com.cloud.resource.SimulatorDiscoverer">
|
||||
<property name="name" value="Simulator Agent"/>
|
||||
</bean>
|
||||
<bean id="SimulatorSecondaryDiscoverer" class="com.cloud.resource.SimulatorSecondaryDiscoverer">
|
||||
</bean>
|
||||
<bean id="SimulatorGuru" class="com.cloud.simulator.SimulatorGuru">
|
||||
<property name="name" value="Simulator Guru"/>
|
||||
</bean>
|
||||
|
|
@ -89,6 +91,7 @@
|
|||
<property name="Adapters">
|
||||
<list>
|
||||
<ref bean="SimulatorDiscoverer"/>
|
||||
<ref bean="SimulatorSecondaryDiscoverer"/>
|
||||
<ref bean="XcpServerDiscoverer"/>
|
||||
<ref bean="SecondaryStorageDiscoverer"/>
|
||||
<ref bean="KvmServerDiscoverer"/>
|
||||
|
|
|
|||
|
|
@ -17,33 +17,52 @@
|
|||
under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloudstack-plugins</artifactId>
|
||||
<version>4.2.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloudstack-plugins</artifactId>
|
||||
<version>4.2.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-plugin-hypervisor-simulator</artifactId>
|
||||
<name>Apache CloudStack Plugin - Hypervisor Simulator</name>
|
||||
<description>Simulator Hypervisor for Cloudstack</description>
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test</testSourceDirectory>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-secondary-storage</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<artifactId>cloud-plugin-hypervisor-simulator</artifactId>
|
||||
<name>Apache CloudStack Plugin - Hypervisor Simulator</name>
|
||||
<description>Simulator Hypervisor for Cloudstack</description>
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-secondary-storage</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-storage</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-storage-image</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-storage-volume</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-storage-snapshot</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -1,107 +0,0 @@
|
|||
// 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.agent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
|
||||
public class MetricsCollector {
|
||||
private static final Logger s_logger = Logger.getLogger(MetricsCollector.class);
|
||||
|
||||
private final Set<String> vmNames = new HashSet<String>();
|
||||
private final Set<String> newVMnames = new HashSet<String>();
|
||||
private final Map<String, MockVmMetrics> metricsMap = new HashMap<String, MockVmMetrics>();
|
||||
|
||||
private final transient ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("Metrics"));
|
||||
|
||||
private Set<String> _currentVms;
|
||||
|
||||
public MetricsCollector(Set<String> currentVms) {
|
||||
_currentVms = currentVms;
|
||||
getAllVMNames();
|
||||
}
|
||||
|
||||
public MetricsCollector() {
|
||||
|
||||
}
|
||||
|
||||
public synchronized void getAllVMNames() {
|
||||
Set<String> currentVMs = _currentVms;
|
||||
|
||||
newVMnames.clear();
|
||||
newVMnames.addAll(currentVMs);
|
||||
newVMnames.removeAll(vmNames); //leave only new vms
|
||||
|
||||
vmNames.removeAll(currentVMs); //old vms - current vms --> leave non-running vms;
|
||||
for (String vm: vmNames) {
|
||||
removeVM(vm);
|
||||
}
|
||||
|
||||
vmNames.clear();
|
||||
vmNames.addAll(currentVMs);
|
||||
}
|
||||
|
||||
public synchronized void submitMetricsJobs() {
|
||||
s_logger.debug("Submit Metric Jobs called");
|
||||
|
||||
for (String vm : newVMnames) {
|
||||
MockVmMetrics task = new MockVmMetrics(vm);
|
||||
if (!metricsMap.containsKey(vm)) {
|
||||
metricsMap.put(vm, task);
|
||||
ScheduledFuture<?> sf = executor.scheduleWithFixedDelay(task, 2, 600, TimeUnit.SECONDS);
|
||||
task.setFuture(sf);
|
||||
}
|
||||
}
|
||||
newVMnames.clear();
|
||||
}
|
||||
|
||||
public synchronized void addVM(String vmName) {
|
||||
newVMnames.add(vmName);
|
||||
s_logger.debug("Added vm name= " + vmName);
|
||||
}
|
||||
|
||||
public synchronized void removeVM(String vmName) {
|
||||
newVMnames.remove(vmName);
|
||||
vmNames.remove(vmName);
|
||||
MockVmMetrics task = metricsMap.get(vmName);
|
||||
if (task != null) {
|
||||
task.stop();
|
||||
boolean r1= task.getFuture().cancel(false);
|
||||
metricsMap.remove(vmName);
|
||||
s_logger.debug("removeVM: cancel returned " + r1 + " for VM " + vmName);
|
||||
} else {
|
||||
s_logger.warn("removeVM called for nonexistent VM " + vmName);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Set<String> getVMNames() {
|
||||
return vmNames;
|
||||
}
|
||||
|
||||
public synchronized Map<String, MockVmMetrics> getMetricsMap() {
|
||||
return metricsMap;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,204 +0,0 @@
|
|||
// 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.agent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MockVmMetrics implements Runnable {
|
||||
private static final Logger s_logger = Logger.getLogger(MockVmMetrics.class);
|
||||
|
||||
private String vmName;
|
||||
|
||||
public final int MAX_INTERFACES=1;
|
||||
|
||||
public final int MAX_DISKS=8;
|
||||
|
||||
//the last calculated traffic speed (transmit) per interface
|
||||
private Map<String, Double> netTxKBps = new HashMap<String, Double>();
|
||||
|
||||
//the last calculated traffic speed (receive) per interface
|
||||
private Map<String, Double> netRxKBps = new HashMap<String, Double>();
|
||||
|
||||
//the last calculated disk write speed per disk (Bytes Per Second)
|
||||
private Map<String, Double> diskWriteKBytesPerSec = new HashMap<String, Double>();
|
||||
|
||||
//the last calculated disk read speed per disk (Bytes Per Second)
|
||||
private Map<String, Double> diskReadKBytesPerSec = new HashMap<String, Double>();
|
||||
|
||||
//Total Bytes Transmitted on network interfaces
|
||||
private Map<String, Long> netTxTotalBytes = new HashMap<String, Long>();
|
||||
|
||||
//Total Bytes Received on network interfaces
|
||||
private Map<String, Long> netRxTotalBytes = new HashMap<String, Long>();
|
||||
|
||||
//Total Bytes read per disk
|
||||
private Map<String, Long> diskReadTotalBytes = new HashMap<String, Long>();
|
||||
|
||||
//Total Bytes written per disk
|
||||
private Map<String, Long> diskWriteTotalBytes = new HashMap<String, Long>();
|
||||
|
||||
//CPU time in seconds
|
||||
private Double cpuSeconds = new Double(0.0);
|
||||
|
||||
//CPU percentage
|
||||
private Float cpuPercent = new Float(0.0);
|
||||
|
||||
private Map<String, String> diskMap = new HashMap<String, String>();
|
||||
|
||||
private Map<String, String> vifMap = new HashMap<String, String>();
|
||||
|
||||
private Map<String, Long> diskStatTimestamp = new HashMap<String, Long>();
|
||||
private Map<String, Long> netStatTimestamp = new HashMap<String, Long>();
|
||||
|
||||
private long cpuStatTimestamp = 0L;
|
||||
|
||||
private ScheduledFuture<?> future;
|
||||
private boolean stopped = false;
|
||||
private Random randSeed = new Random();
|
||||
|
||||
public MockVmMetrics(String vmName) {
|
||||
this.vmName = vmName;
|
||||
vifMap.put("eth0", "eth0");
|
||||
vifMap.put("eth1", "eth1");
|
||||
vifMap.put("eth2", "eth2");
|
||||
|
||||
Long networkStart = 0L;
|
||||
netTxTotalBytes.put("eth0", networkStart);
|
||||
netRxTotalBytes.put("eth0", networkStart);
|
||||
|
||||
netTxTotalBytes.put("eth1", networkStart);
|
||||
netRxTotalBytes.put("eth1", networkStart);
|
||||
|
||||
netTxTotalBytes.put("eth2", networkStart);
|
||||
netRxTotalBytes.put("eth2", networkStart);
|
||||
}
|
||||
|
||||
private int getIncrementor() {
|
||||
return randSeed.nextInt(100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Generating MockVM metrics");
|
||||
}
|
||||
for (Map.Entry<String, Long> entry : netRxTotalBytes.entrySet()) {
|
||||
entry.setValue(entry.getValue() + getIncrementor());
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Long> entry : netTxTotalBytes.entrySet()) {
|
||||
entry.setValue(entry.getValue() + getIncrementor());
|
||||
}
|
||||
}
|
||||
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
|
||||
public Map<String, Double> getNetTxKBps() {
|
||||
return netTxKBps;
|
||||
}
|
||||
|
||||
public Map<String, Double> getNetRxKBps() {
|
||||
return netRxKBps;
|
||||
}
|
||||
|
||||
public Map<String, Double> getDiskWriteBytesPerSec() {
|
||||
return diskWriteKBytesPerSec;
|
||||
}
|
||||
|
||||
public Map<String, Double> getDiskReadBytesPerSec() {
|
||||
return diskReadKBytesPerSec;
|
||||
}
|
||||
|
||||
public Map<String, Long> getNetTxTotalBytes() {
|
||||
return netTxTotalBytes;
|
||||
}
|
||||
|
||||
public Map<String, Long> getNetRxTotalBytes() {
|
||||
return netRxTotalBytes;
|
||||
}
|
||||
|
||||
public Map<String, Long> getDiskReadTotalBytes() {
|
||||
return diskReadTotalBytes;
|
||||
}
|
||||
|
||||
public Map<String, Long> getDiskWriteTotalBytes() {
|
||||
return diskWriteTotalBytes;
|
||||
}
|
||||
|
||||
public Double getNetTxKBps(String intf) {
|
||||
return netTxKBps.get(intf);
|
||||
}
|
||||
|
||||
public Double getNetRxKBps(String intf) {
|
||||
return netRxKBps.get(intf);
|
||||
}
|
||||
|
||||
public Double getDiskWriteKBytesPerSec(String disk) {
|
||||
return diskWriteKBytesPerSec.get(disk);
|
||||
}
|
||||
|
||||
public Double getDiskReadKBytesPerSec(String disk) {
|
||||
return diskReadKBytesPerSec.get(disk);
|
||||
}
|
||||
|
||||
public Long getNetTxTotalBytes(String intf) {
|
||||
return netTxTotalBytes.get(intf);
|
||||
}
|
||||
|
||||
public Long getNetRxTotalBytes(String intf) {
|
||||
return netRxTotalBytes.get(intf);
|
||||
}
|
||||
|
||||
public Long getDiskReadTotalBytes(String disk) {
|
||||
return diskReadTotalBytes.get(disk);
|
||||
}
|
||||
|
||||
public Long getDiskWriteTotalBytes(String disk) {
|
||||
return diskWriteTotalBytes.get(disk);
|
||||
}
|
||||
|
||||
public Double getCpuSeconds() {
|
||||
return cpuSeconds;
|
||||
}
|
||||
|
||||
public Map<String, String> getDiskMap() {
|
||||
return diskMap;
|
||||
}
|
||||
|
||||
public Float getCpuPercent() {
|
||||
return cpuPercent;
|
||||
}
|
||||
|
||||
public void setFuture(ScheduledFuture<?> sf) {
|
||||
this.future = sf;
|
||||
}
|
||||
|
||||
public ScheduledFuture<?> getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.stopped = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
// 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.agent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MulticastSocket;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MultiCaster implements Runnable {
|
||||
private static final Logger s_logger = Logger.getLogger(MultiCaster.class);
|
||||
|
||||
public final int MAX_PACKET_SIZE = 8096;
|
||||
|
||||
private List<MultiCasterListener> listeners;
|
||||
private DatagramSocket socket;
|
||||
private byte[] recvBuffer;
|
||||
|
||||
private Thread driver;
|
||||
private volatile boolean stopRequested = false;
|
||||
|
||||
public MultiCaster() {
|
||||
listeners = new ArrayList<MultiCasterListener>();
|
||||
recvBuffer = new byte[MAX_PACKET_SIZE];
|
||||
}
|
||||
|
||||
public void addListener(MultiCasterListener listener) {
|
||||
synchronized(listeners) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeListener(MultiCasterListener listener) {
|
||||
synchronized(listeners) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void cast(byte[] buf, int off, int len,
|
||||
InetAddress toAddress, int nToPort) throws IOException {
|
||||
|
||||
if(socket == null)
|
||||
throw new IOException("multi caster is not started");
|
||||
|
||||
if(len >= MAX_PACKET_SIZE)
|
||||
throw new IOException("packet size exceeds limit of " + MAX_PACKET_SIZE);
|
||||
|
||||
DatagramPacket packet = new DatagramPacket(buf, off,
|
||||
len, toAddress, nToPort);
|
||||
|
||||
socket.send(packet);
|
||||
}
|
||||
|
||||
public void start(String strOutboundAddress,
|
||||
String strClusterAddress, int nPort) throws SocketException {
|
||||
assert(socket == null);
|
||||
|
||||
InetAddress addr = null;
|
||||
try {
|
||||
addr = InetAddress.getByName(strClusterAddress);
|
||||
} catch(IOException e) {
|
||||
s_logger.error("Unexpected exception " , e);
|
||||
}
|
||||
|
||||
if(addr != null && addr.isMulticastAddress()) {
|
||||
try {
|
||||
socket = new MulticastSocket(nPort);
|
||||
socket.setReuseAddress(true);
|
||||
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Join multicast group : " + addr);
|
||||
|
||||
((MulticastSocket)socket).joinGroup(addr);
|
||||
((MulticastSocket)socket).setTimeToLive(1);
|
||||
|
||||
if(strOutboundAddress != null) {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("set outgoing interface to : " + strOutboundAddress);
|
||||
|
||||
InetAddress ia = InetAddress.getByName(strOutboundAddress);
|
||||
NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
|
||||
((MulticastSocket)socket).setNetworkInterface(ni);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
s_logger.error("Unexpected exception " , e);
|
||||
}
|
||||
} else {
|
||||
socket = new DatagramSocket(nPort);
|
||||
socket.setReuseAddress(true);
|
||||
}
|
||||
|
||||
driver = new Thread(this, "Multi-caster");
|
||||
driver.setDaemon(true);
|
||||
driver.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if(socket != null) {
|
||||
stopRequested = true;
|
||||
|
||||
socket.close();
|
||||
if(driver != null) {
|
||||
try {
|
||||
driver.join();
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
driver = null;
|
||||
}
|
||||
}
|
||||
|
||||
socket = null;
|
||||
stopRequested = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while(!stopRequested) {
|
||||
try {
|
||||
DatagramPacket packet = new DatagramPacket(recvBuffer, recvBuffer.length);
|
||||
socket.receive(packet);
|
||||
|
||||
for(Object listener : listeners.toArray()) {
|
||||
((MultiCasterListener)listener).onMultiCasting(packet.getData(),
|
||||
packet.getOffset(), packet.getLength(), packet.getAddress());
|
||||
}
|
||||
} catch(IOException e) {
|
||||
} catch(Throwable e) {
|
||||
s_logger.error("Unhandled exception : ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
// 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.agent;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public interface MultiCasterListener {
|
||||
public void onMultiCasting(byte[] data, int off, int len, InetAddress addrFrom);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// 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.agent;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SimulatorCmd implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String testCase = "DEFAULT";
|
||||
|
||||
public SimulatorCmd(String testCase) {
|
||||
this.testCase = testCase;
|
||||
}
|
||||
|
||||
public String getTestCase() {
|
||||
return testCase;
|
||||
}
|
||||
|
||||
public void setTestCase(String testCase) {
|
||||
this.testCase = testCase;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
// 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.agent;
|
||||
|
||||
public class SimulatorMigrateVmCmd extends SimulatorCmd {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String destIp;
|
||||
|
||||
private String vmName;
|
||||
private long ramSize;
|
||||
private int cpuCount;
|
||||
private int utilization;
|
||||
|
||||
public SimulatorMigrateVmCmd(String testCase) {
|
||||
super(testCase);
|
||||
}
|
||||
|
||||
public String getDestIp() {
|
||||
return destIp;
|
||||
}
|
||||
|
||||
public void setDestIp(String destIp) {
|
||||
this.destIp = destIp;
|
||||
}
|
||||
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
|
||||
public void setVmName(String vmName) {
|
||||
this.vmName = vmName;
|
||||
}
|
||||
|
||||
public long getRamSize() {
|
||||
return ramSize;
|
||||
}
|
||||
|
||||
public void setRamSize(long ramSize) {
|
||||
this.ramSize = ramSize;
|
||||
}
|
||||
|
||||
public int getCpuCount() {
|
||||
return cpuCount;
|
||||
}
|
||||
|
||||
public void setCpuCount(int cpuCount) {
|
||||
this.cpuCount = cpuCount;
|
||||
}
|
||||
|
||||
public int getUtilization() {
|
||||
return utilization;
|
||||
}
|
||||
|
||||
public void setUtilization(int utilization) {
|
||||
this.utilization = utilization;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("SimulatorMigrateVmCmd {").append("vm: ").append(getVmName());
|
||||
sb.append(", destIp: ").append(getDestIp()).append(", ramSize: ").append(getRamSize());
|
||||
sb.append(", cpuCount: ").append(getCpuCount()).append(", utilization: ").append(getUtilization());
|
||||
sb.append("}");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
18
plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
Executable file → Normal file
18
plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
Executable file → Normal file
|
|
@ -26,11 +26,10 @@ import com.cloud.agent.api.GetHostStatsCommand;
|
|||
import com.cloud.agent.api.HostStatsEntry;
|
||||
import com.cloud.agent.api.MaintainAnswer;
|
||||
import com.cloud.agent.api.PingTestCommand;
|
||||
import com.cloud.api.commands.SimulatorAddSecondaryAgent;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.resource.AgentResourceBase;
|
||||
import com.cloud.resource.AgentRoutingResource;
|
||||
import com.cloud.resource.AgentStorageResource;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.resource.*;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.simulator.MockHostVO;
|
||||
import com.cloud.simulator.MockVMVO;
|
||||
|
|
@ -43,6 +42,7 @@ import com.cloud.utils.db.DB;
|
|||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -79,6 +79,8 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
|
|||
MockStorageManager _storageMgr = null;
|
||||
@Inject
|
||||
ResourceManager _resourceMgr;
|
||||
@Inject
|
||||
SimulatorSecondaryDiscoverer discoverer;
|
||||
private SecureRandom random;
|
||||
private final Map<String, AgentResourceBase> _resources = new ConcurrentHashMap<String, AgentResourceBase>();
|
||||
private ThreadPoolExecutor _executor;
|
||||
|
|
@ -325,6 +327,14 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
|
|||
storageResource.configure("secondaryStorage", params);
|
||||
storageResource.start();
|
||||
_resources.put(this.guid, storageResource);
|
||||
discoverer.setResource(storageResource);
|
||||
SimulatorAddSecondaryAgent cmd = new SimulatorAddSecondaryAgent("sim://" + this.guid, this.dcId);
|
||||
try {
|
||||
_resourceMgr.discoverHosts(cmd);
|
||||
} catch (DiscoveryException e) {
|
||||
s_logger.debug("Failed to discover host: " + e.toString());
|
||||
return;
|
||||
}
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.debug("Failed to load secondary storage resource: " + e.toString());
|
||||
return;
|
||||
|
|
|
|||
0
plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManager.java
Executable file → Normal file
0
plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManager.java
Executable file → Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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.api.commands;
|
||||
|
||||
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
|
||||
|
||||
public class SimulatorAddSecondaryAgent extends AddSecondaryStorageCmd {
|
||||
public SimulatorAddSecondaryAgent(String url, Long zoneId) {
|
||||
this.url = url;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
package com.cloud.resource;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -25,6 +26,7 @@ import javax.inject.Inject;
|
|||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.storage.resource.SecondaryStorageDiscoverer;
|
||||
import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
|
|
@ -52,6 +54,11 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer imp
|
|||
@Inject AgentManager _agentMgr;
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
@Inject SnapshotDao _snapshotDao;
|
||||
protected SecondaryStorageResource resource;
|
||||
|
||||
public void setResource(SecondaryStorageResource resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
|
|
@ -62,27 +69,18 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer imp
|
|||
|
||||
@Override
|
||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI uri, String username, String password, List<String> hostTags) {
|
||||
if (!uri.getScheme().equalsIgnoreCase("nfs") && !uri.getScheme().equalsIgnoreCase("file")
|
||||
&& !uri.getScheme().equalsIgnoreCase("iso") && !uri.getScheme().equalsIgnoreCase("dummy")) {
|
||||
if (!uri.getScheme().equalsIgnoreCase("sim")) {
|
||||
s_logger.debug("It's not NFS or file or ISO, so not a secondary storage server: " + uri.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (uri.getScheme().equalsIgnoreCase("nfs") || uri.getScheme().equalsIgnoreCase("iso")) {
|
||||
return createNfsSecondaryStorageResource(dcId, podId, uri);
|
||||
} else if (uri.getScheme().equalsIgnoreCase("file")) {
|
||||
return createLocalSecondaryStorageResource(dcId, podId, uri);
|
||||
} else if (uri.getScheme().equalsIgnoreCase("dummy")) {
|
||||
return createDummySecondaryStorageResource(dcId, podId, uri);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
Map<SecondaryStorageResource, Map<String, String>> resources = new HashMap<SecondaryStorageResource, Map<String, String>>();
|
||||
resources.put(this.resource, new HashMap<String, String>());
|
||||
return resources;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void postDiscovery(List<HostVO> hosts, long msId) {
|
||||
super.postDiscovery(hosts, msId);
|
||||
for (HostVO host: hosts) {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Preinstalling simulator templates");
|
||||
|
|
|
|||
|
|
@ -26,19 +26,28 @@ import com.cloud.agent.api.to.DataStoreTO;
|
|||
import com.cloud.agent.api.to.NfsTO;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.framework.async.AsyncRpcContext;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.BaseImageStoreDriverImpl;
|
||||
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SimulatorImageStoreDriverImpl extends BaseImageStoreDriverImpl {
|
||||
|
|
@ -68,7 +77,7 @@ public class SimulatorImageStoreDriverImpl extends BaseImageStoreDriverImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createAsync(DataStore store, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
if (data.getType() == DataObjectType.TEMPLATE) {
|
||||
this.createTemplate(data, callback);
|
||||
} else if (data.getType() == DataObjectType.VOLUME) {
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 org.apache.cloudstack.storage.motion;
|
||||
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.host.Host;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.*;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SimulatorDataMotionStrategy implements DataMotionStrategy {
|
||||
@Override
|
||||
public boolean canHandle(DataObject srcData, DataObject destData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(Map<VolumeInfo, DataStore> volumeMap, Host srcHost, Host destHost) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
|
||||
CopyCommandResult result = new CopyCommandResult("something", null);
|
||||
callback.complete(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void copyAsync(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
|
||||
CopyCommandResult result = new CopyCommandResult("something", null);
|
||||
callback.complete(result);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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 org.apache.cloudstack.storage.resource;
|
||||
|
||||
public class SimulatorSecondaryStorageResource extends NfsSecondaryStorageResource {
|
||||
|
||||
}
|
||||
|
|
@ -65,7 +65,6 @@
|
|||
<module>storage/image/swift</module>
|
||||
<module>storage/image/default</module>
|
||||
<module>storage/image/sample</module>
|
||||
<module>storage/image/simulator</module>
|
||||
<module>storage/volume/solidfire</module>
|
||||
<module>storage/volume/default</module>
|
||||
<module>storage/volume/sample</module>
|
||||
|
|
@ -159,7 +158,6 @@
|
|||
</activation>
|
||||
<modules>
|
||||
<module>hypervisors/simulator</module>
|
||||
<module>storage/image/simulator</module>
|
||||
</modules>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
<!-- 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. -->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cloud-plugin-storage-image-simulator</artifactId>
|
||||
<name>Apache CloudStack Plugin - Storage Image Simulator provider</name>
|
||||
<parent>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloudstack-plugins</artifactId>
|
||||
<version>4.2.0-SNAPSHOT</version>
|
||||
<relativePath>../../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-storage</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-storage-image</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-storage-volume</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-storage-snapshot</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${cs.mysql.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
Loading…
Reference in New Issue