Merge branch 'master' into add_remove_nics

This commit is contained in:
Marcus Sorensen 2013-01-25 22:23:42 -07:00
commit ea7fbd6b4f
95 changed files with 5348 additions and 2574 deletions

View File

@ -69,3 +69,14 @@ domr.scripts.dir=scripts/network/domr/kvm
# set the vm migrate speed, by default, it will try to guess the speed of the guest network
# In MegaBytes per second
#vm.migrate.speed=0
# set the type of bridge used on the hypervisor, this defines what commands the resource
# will use to setup networking. Currently supported NATIVE, OPENVSWITCH
#network.bridge.type=native
# set the driver used to plug and unplug nics from the bridges
# a sensible default will be selected based on the network.bridge.type but can
# be overridden here.
# native = com.cloud.hypervisor.kvm.resource.BridgeVifDriver
# openvswitch = com.cloud.hypervisor.kvm.resource.OvsBridgeDriver
#libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.BridgeVifDriver

View File

@ -47,6 +47,15 @@ public interface EntityManager {
*/
public <T> T findByUuid(Class<T> entityType, String uuid);
/**
* Finds a unique entity by uuid string
* @param <T> entity class
* @param entityType type of entity you're looking for.
* @param uuid the unique id
* @return T if found, null if not.
*/
public <T> T findByUuidIncludingRemoved(Class<T> entityType, String uuid);
/**
* Finds an entity by external id which is always String
* @param <T> entity class

View File

@ -34,6 +34,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.org.Cluster;
import com.cloud.storage.S3;
import com.cloud.storage.Swift;
import com.cloud.utils.Pair;
import com.cloud.utils.fsm.NoTransitionException;
import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd;
@ -94,10 +95,10 @@ public interface ResourceService {
Swift discoverSwift(AddSwiftCmd addSwiftCmd) throws DiscoveryException;
S3 discoverS3(AddS3Cmd cmd) throws DiscoveryException;
List<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId);
List<? extends Swift> listSwifts(ListSwiftsCmd cmd);
Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd);
List<? extends S3> listS3s(ListS3sCmd cmd);

View File

@ -93,16 +93,6 @@ import com.cloud.vm.VirtualMachine.Type;
public interface ManagementService {
static final String Name = "management-server";
/**
* Retrieves the list of data centers with search criteria. Currently the only search criteria is "available" zones
* for the
* account that invokes the API. By specifying available=true all zones which the account can access. By specifying
* available=false the zones where the account has virtual machine instances will be returned.
*
* @return a list of DataCenters
*/
List<? extends DataCenter> listDataCenters(ListZonesByCmd cmd);
/**
* returns the a map of the names/values in the configuraton table
*
@ -110,13 +100,6 @@ public interface ManagementService {
*/
Pair<List<? extends Configuration>, Integer> searchForConfigurations(ListCfgsByCmd c);
/**
* Searches for Service Offerings by the specified search criteria Can search by: "name"
*
* @param cmd
* @return List of ServiceOfferings
*/
List<? extends ServiceOffering> searchForServiceOfferings(ListServiceOfferingsCmd cmd);
/**
* Searches for Clusters by the specified search criteria
@ -144,7 +127,7 @@ public interface ManagementService {
/**
* Searches for servers by the specified search criteria Can search by: "name", "type", "state", "dataCenterId",
* "podId"
*
*
* @param cmd
* @return List of Hosts
*/
@ -243,15 +226,6 @@ public interface ManagementService {
*/
Set<Pair<Long, Long>> listTemplates(ListTemplatesCmd cmd);
/**
* Search for disk offerings based on search criteria
*
* @param cmd
* the command containing the criteria to use for searching for disk offerings
* @return a list of disk offerings that match the given criteria
*/
List<? extends DiskOffering> searchForDiskOfferings(ListDiskOfferingsCmd cmd);
/**
* List system VMs by the given search criteria

View File

@ -82,7 +82,7 @@ public interface SnapshotService {
* the command that specifies the volume criteria
* @return list of snapshot policies
*/
List<? extends SnapshotPolicy> listPoliciesforVolume(ListSnapshotPoliciesCmd cmd);
Pair<List<? extends SnapshotPolicy>, Integer> listPoliciesforVolume(ListSnapshotPoliciesCmd cmd);
boolean deleteSnapshotPolicies(DeleteSnapshotPoliciesCmd cmd);

View File

@ -18,7 +18,7 @@ package org.apache.cloudstack.api;
public abstract class BaseListAccountResourcesCmd extends BaseListDomainResourcesCmd {
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "List resources by account. Must be used with the domainId parameter.")
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "list resources by account. Must be used with the domainId parameter.")
private String accountName;
public String getAccountName() {

View File

@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map;
import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
@ -69,7 +69,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.CONSERVE_MODE, type=CommandType.BOOLEAN, description="true if the network offering is IP conserve mode enabled")
private Boolean conserveMode;
@Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.UUID, entityType=DiskOfferingResponse.class,
@Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.UUID, entityType=ServiceOfferingResponse.class,
description="the service offering ID used by virtual router provider")
private Long serviceOfferingId;

View File

@ -30,6 +30,7 @@ import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.SwiftResponse;
import com.cloud.storage.Swift;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
@APICommand(name = "listSwifts", description = "List Swift.", responseObject = HostResponse.class, since="3.0.0")
public class ListSwiftsCmd extends BaseListCmd {
@ -64,20 +65,19 @@ public class ListSwiftsCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends Swift> result = _resourceService.listSwifts(this);
Pair<List<? extends Swift>, Integer> result = _resourceService.listSwifts(this);
ListResponse<SwiftResponse> response = new ListResponse<SwiftResponse>();
List<SwiftResponse> swiftResponses = new ArrayList<SwiftResponse>();
if (result != null) {
SwiftResponse swiftResponse = null;
for (Swift swift : result) {
swiftResponse = _responseGenerator.createSwiftResponse(swift);
for (Swift swift : result.first()) {
SwiftResponse swiftResponse = _responseGenerator.createSwiftResponse(swift);
swiftResponse.setResponseName(getCommandName());
swiftResponse.setObjectName("swift");
swiftResponses.add(swiftResponse);
}
}
response.setResponses(swiftResponses);
response.setResponses(swiftResponses, result.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -47,7 +47,7 @@ public class AttachIsoCmd extends BaseAsyncCmd {
required=true, description="the ID of the ISO file")
private Long id;
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = TemplateResponse.class,
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = UserVmResponse.class,
required=true, description="the ID of the virtual machine")
private Long virtualMachineId;

View File

@ -42,7 +42,7 @@ public class DetachIsoCmd extends BaseAsyncCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = TemplateResponse.class,
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = UserVmResponse.class,
required=true, description="The ID of the virtual machine")
private Long virtualMachineId;

View File

@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ListResponse;
@ -78,16 +79,8 @@ public class ListDiskOfferingsCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends DiskOffering> result = _mgr.searchForDiskOfferings(this);
ListResponse<DiskOfferingResponse> response = new ListResponse<DiskOfferingResponse>();
List<DiskOfferingResponse> diskOfferingResponses = new ArrayList<DiskOfferingResponse>();
for (DiskOffering offering : result) {
DiskOfferingResponse diskOffResp = _responseGenerator.createDiskOfferingResponse(offering);
diskOffResp.setObjectName("diskoffering");
diskOfferingResponses.add(diskOffResp);
}
response.setResponses(diskOfferingResponses);
ListResponse<DiskOfferingResponse> response = _queryService.searchForDiskOfferings(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -16,9 +16,6 @@
// under the License.
package org.apache.cloudstack.api.command.user.offering;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
@ -29,7 +26,6 @@ import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import com.cloud.offering.ServiceOffering;
@APICommand(name = "listServiceOfferings", description="Lists all available service offerings.", responseObject=ServiceOfferingResponse.class)
public class ListServiceOfferingsCmd extends BaseListCmd {
@ -102,17 +98,10 @@ public class ListServiceOfferingsCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends ServiceOffering> offerings = _mgr.searchForServiceOfferings(this);
ListResponse<ServiceOfferingResponse> response = new ListResponse<ServiceOfferingResponse>();
List<ServiceOfferingResponse> offeringResponses = new ArrayList<ServiceOfferingResponse>();
for (ServiceOffering offering : offerings) {
ServiceOfferingResponse offeringResponse = _responseGenerator.createServiceOfferingResponse(offering);
offeringResponse.setObjectName("serviceoffering");
offeringResponses.add(offeringResponse);
}
response.setResponses(offeringResponses);
ListResponse<ServiceOfferingResponse> response = _queryService.searchForServiceOfferings(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -29,6 +29,7 @@ import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.SnapshotPolicyResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import com.cloud.storage.snapshot.SnapshotPolicy;
import com.cloud.utils.Pair;
@APICommand(name = "listSnapshotPolicies", description="Lists snapshot policies.", responseObject=SnapshotPolicyResponse.class)
public class ListSnapshotPoliciesCmd extends BaseListCmd {
@ -63,15 +64,15 @@ public class ListSnapshotPoliciesCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends SnapshotPolicy> result = _snapshotService.listPoliciesforVolume(this);
Pair<List<? extends SnapshotPolicy>, Integer> result = _snapshotService.listPoliciesforVolume(this);
ListResponse<SnapshotPolicyResponse> response = new ListResponse<SnapshotPolicyResponse>();
List<SnapshotPolicyResponse> policyResponses = new ArrayList<SnapshotPolicyResponse>();
for (SnapshotPolicy policy : result) {
for (SnapshotPolicy policy : result.first()) {
SnapshotPolicyResponse policyResponse = _responseGenerator.createSnapshotPolicyResponse(policy);
policyResponse.setObjectName("snapshotpolicy");
policyResponses.add(policyResponse);
}
response.setResponses(policyResponses);
response.setResponses(policyResponses, result.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -51,7 +51,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
required=true, description="ID of the zone the template is being copied to.")
private Long destZoneId;
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class,
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class,
required=true, description="Template ID.")
private Long id;

View File

@ -17,7 +17,7 @@
package org.apache.cloudstack.api.command.user.template;
import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.TemplateResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
@ -38,7 +38,7 @@ public class DeleteTemplateCmd extends BaseAsyncCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class,
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class,
required=true, description="the ID of the template")
private Long id;

View File

@ -17,7 +17,7 @@
package org.apache.cloudstack.api.command.user.template;
import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.TemplateResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
@ -40,7 +40,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class,
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class,
required=true, description="the ID of the template")
private Long id;

View File

@ -64,15 +64,6 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd{
, description="list by ID of the VPC offering")
private Long VpcOffId;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list by account associated with the VPC. " +
"Must be used with the domainId parameter.")
private String accountName;
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class,
description="list by domain ID associated with the VPC. " +
"If used with the account parameter returns the VPC associated with the account for the specified domain.")
private Long domainId;
@Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING,
description="list VPC supporting certain services")
private List<String> supportedServices;
@ -87,14 +78,6 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd{
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getAccountName() {
return accountName;
}
public Long getDomainId() {
return domainId;
}
public Long getZoneId() {
return zoneId;
}

View File

@ -27,6 +27,7 @@ import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import com.cloud.dc.DataCenter;
@ -86,16 +87,8 @@ public class ListZonesByCmd extends BaseListCmd {
@Override
public void execute(){
List<? extends DataCenter> dataCenters = _mgr.listDataCenters(this);
ListResponse<ZoneResponse> response = new ListResponse<ZoneResponse>();
List<ZoneResponse> zoneResponses = new ArrayList<ZoneResponse>();
for (DataCenter dataCenter : dataCenters) {
ZoneResponse zoneResponse = _responseGenerator.createZoneResponse(dataCenter, showCapacities);
zoneResponse.setObjectName("zone");
zoneResponses.add(zoneResponse);
}
response.setResponses(zoneResponses);
ListResponse<ZoneResponse> response = _queryService.listDataCenters(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -65,8 +65,8 @@ public class ZoneResponse extends BaseResponse {
@SerializedName(ApiConstants.DOMAIN) @Param(description="Network domain name for the networks in the zone")
private String domain;
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the ID of the containing domain, null for public zones")
private Long domainId;
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the UUID of the containing domain, null for public zones")
private String domainId;
@SerializedName("domainname") @Param(description="the name of the containing domain, null for public zones")
private String domainName;
@ -140,7 +140,7 @@ public class ZoneResponse extends BaseResponse {
this.domain = domain;
}
public void setDomainId(Long domainId) {
public void setDomainId(String domainId) {
this.domainId = domainId;
}

View File

@ -26,6 +26,8 @@ import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd;
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
@ -33,8 +35,10 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
@ -45,10 +49,12 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse;
import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
@ -92,4 +98,10 @@ public interface QueryService {
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd);
public ListResponse<AsyncJobResponse> searchForAsyncJobs(ListAsyncJobsCmd cmd);
public ListResponse<DiskOfferingResponse> searchForDiskOfferings(ListDiskOfferingsCmd cmd);
public ListResponse<ServiceOfferingResponse> searchForServiceOfferings(ListServiceOfferingsCmd cmd);
public ListResponse<ZoneResponse> listDataCenters(ListZonesByCmd cmd);
}

View File

@ -1359,8 +1359,8 @@ label.type=Type
label.unavailable=Unavailable
label.unlimited=Unlimited
label.untagged=Untagged
label.update.ssl.cert=Update SSL Certificate
label.update.ssl=Update SSL Certificate
label.update.ssl.cert= SSL Certificate
label.update.ssl= SSL Certificate
label.updating=Updating
label.url=URL
label.usage.interface=Usage Interface

View File

@ -83,6 +83,11 @@
<para>Make sure the new host has the same network configuration (guest, private, and
public network) as other hosts in the cluster.</para>
</listitem>
<listitem>
<para>If you are using OpenVswitch bridges edit the file agent.properties on the KVM host
and set the parameter <emphasis role="italic">network.bridge.type</emphasis> to
<emphasis role="italic">openvswitch</emphasis> before adding the host to &PRODUCT;</para>
</listitem>
</itemizedlist>
</section>
<!-- <section>

View File

@ -0,0 +1,116 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
<!-- 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.
-->
<section id="hypervisor-host-install-network-openvswitch">
<title>Configure the network using OpenVswitch</title>
<warning><para>This is a very important section, please make sure you read this thoroughly.</para></warning>
<para>In order to forward traffic to your instances you will need at least two bridges: <emphasis>public</emphasis> and <emphasis>private</emphasis>.</para>
<para>By default these bridges are called <emphasis>cloudbr0</emphasis> and <emphasis>cloudbr1</emphasis>, but you do have to make sure they are available on each hypervisor.</para>
<para>The most important factor is that you keep the configuration consistent on all your hypervisors.</para>
<section id="hypervisor-host-install-network-openvswitch-prepare">
<title>Preparing</title>
<para>To make sure that the native bridge module will not interfere with openvswitch the bridge module should be added to the blacklist. See the modprobe documentation for your distribution on where to find the blacklist. Make sure the module is not loaded either by rebooting or executing rmmod bridge before executing next steps.</para>
<para>The network configurations below depend on the ifup-ovs and ifdown-ovs scripts which are part of the openvswitch installation. They should be installed in /etc/sysconfig/network-scripts/</para>
</section>
<section id="hypervisor-host-install-network-openvswitch-vlan">
<title>Network example</title>
<para>There are many ways to configure your network. In the Basic networking mode you should have two (V)LAN's, one for your private network and one for the public network.</para>
<para>We assume that the hypervisor has one NIC (eth0) with three tagged VLAN's:</para>
<orderedlist>
<listitem><para>VLAN 100 for management of the hypervisor</para></listitem>
<listitem><para>VLAN 200 for public network of the instances (cloudbr0)</para></listitem>
<listitem><para>VLAN 300 for private network of the instances (cloudbr1)</para></listitem>
</orderedlist>
<para>On VLAN 100 we give the Hypervisor the IP-Address 192.168.42.11/24 with the gateway 192.168.42.1</para>
<note><para>The Hypervisor and Management server don't have to be in the same subnet!</para></note>
</section>
<section id="hypervisor-host-install-network-openvswitch-configure">
<title>Configuring the network bridges</title>
<para>It depends on the distribution you are using how to configure these, below you'll find
examples for RHEL/CentOS.</para>
<note><para>The goal is to have three bridges called 'mgmt0', 'cloudbr0' and 'cloudbr1' after this
section. This should be used as a guideline only. The exact configuration will
depend on your network layout.</para></note>
<section id="hypervisor-host-install-network-openvswitch-configure-ovs">
<title>Configure OpenVswitch</title>
<para>The network interfaces using OpenVswitch are created using the ovs-vsctl command. This command will configure the interfaces and persist them to the OpenVswitch database.</para>
<para>First we create a main bridge connected to the eth0 interface. Next we create three fake bridges, each connected to a specific vlan tag.</para>
<programlisting><![CDATA[# ovs-vsctl add-br cloudbr
# ovs-vsctl add-port cloudbr eth0
# ovs-vsctl set port cloudbr trunks=100,200,300
# ovs-vsctl add-br mgmt0 cloudbr 100
# ovs-vsctl add-br cloudbr0 cloudbr 200
# ovs-vsctl add-br cloudbr1 cloudbr 300]]></programlisting>
</section>
<section id="hypervisor-host-install-network-openvswitch-configure-rhel">
<title>Configure in RHEL or CentOS</title>
<para>The required packages were installed when openvswitch and libvirt were installed,
we can proceed to configuring the network.</para>
<para>First we configure eth0</para>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-eth0</programlisting>
<para>Make sure it looks similair to:</para>
<programlisting><![CDATA[DEVICE=eth0
HWADDR=00:04:xx:xx:xx:xx
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=none
TYPE=Ethernet]]></programlisting>
<para>We have to configure the base bridge with the trunk.</para>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-cloudbr</programlisting>
<programlisting><![CDATA[DEVICE=cloudbr
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=none
DEVICETYPE=ovs
TYPE=OVSBridge]]></programlisting>
<para>We now have to configure the three VLAN bridges:</para>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-mgmt0</programlisting>
<programlisting><![CDATA[DEVICE=mgmt0
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=static
DEVICETYPE=ovs
TYPE=OVSBridge
IPADDR=192.168.42.11
GATEWAY=192.168.42.1
NETMASK=255.255.255.0]]></programlisting>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-cloudbr0</programlisting>
<programlisting><![CDATA[DEVICE=cloudbr0
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=none
DEVICETYPE=ovs
TYPE=OVSBridge]]></programlisting>
<programlisting language="Bash">vi /etc/sysconfig/network-scripts/ifcfg-cloudbr1</programlisting>
<programlisting><![CDATA[DEVICE=cloudbr1
ONBOOT=yes
HOTPLUG=no
BOOTPROTO=none
TYPE=OVSBridge
DEVICETYPE=ovs]]></programlisting>
<para>With this configuration you should be able to restart the network, although a reboot is recommended to see if everything works properly.</para>
<warning><para>Make sure you have an alternative way like IPMI or ILO to reach the machine in case you made a configuration error and the network stops functioning!</para></warning>
</section>
</section>
</section>

View File

@ -25,6 +25,7 @@
<section id="hypervisor-host-install-network">
<title>Configure the network bridges</title>
<warning><para>This is a very important section, please make sure you read this thoroughly.</para></warning>
<note><para>This section details how to configure bridges using the native implementation in Linux. Please refer to the next section if you intend to use OpenVswitch</para></note>
<para>In order to forward traffic to your instances you will need at least two bridges: <emphasis>public</emphasis> and <emphasis>private</emphasis>.</para>
<para>By default these bridges are called <emphasis>cloudbr0</emphasis> and <emphasis>cloudbr1</emphasis>, but you do have to make sure they are available on each hypervisor.</para>
<para>The most important factor is that you keep the configuration consistent on all your hypervisors.</para>
@ -146,4 +147,4 @@ iface cloudbr1 inet manual
<warning><para>Make sure you have an alternative way like IPMI or ILO to reach the machine in case you made a configuration error and the network stops functioning!</para></warning>
</section>
</section>
</section>
</section>

View File

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
@ -31,6 +31,7 @@
<xi:include href="hypervisor-host-install-libvirt.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-security-policies.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-network.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-network-openvswitch.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-firewall.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="hypervisor-host-install-finish.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</section>

View File

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
@ -35,6 +35,11 @@
<listitem><para>libvirt: 0.9.4 or higher</para></listitem>
<listitem><para>Qemu/KVM: 1.0 or higher</para></listitem>
</itemizedlist>
<para>The default bridge in &PRODUCT; is the Linux native bridge implementation (bridge module). &PRODUCT; includes an option to work with OpenVswitch, the requirements are listed below</para>
<itemizedlist>
<listitem><para>libvirt: 0.9.11 or higher</para></listitem>
<listitem><para>openvswitch: 1.7.1 or higher</para></listitem>
</itemizedlist>
<para>In addition, the following hardware requirements apply:</para>
<itemizedlist>
<listitem><para>Within a single cluster, the hosts must be of the same distribution version.</para></listitem>

View File

@ -1,25 +1,22 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
<!-- 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.
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.
-->
<chapter id="offerings">
@ -28,4 +25,5 @@
are discussed in the section on setting up networking for users.</para>
<xi:include href="compute-disk-service-offerings.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="system-service-offerings.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="sys-offering-sysvm.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</chapter>

View File

@ -24,6 +24,10 @@
<title>Features of the Nicira NVP Plugin</title>
<para>In CloudStack release 4.0.0-incubating this plugin supports the Connectivity service. This service is responsible for creating Layer 2 networks supporting the networks created by Guests. In other words when an tennant creates a new network, instead of the traditional VLAN a logical network will be created by sending the appropriate calls to the Nicira NVP Controller.</para>
<para>The plugin has been tested with Nicira NVP versions 2.1.0, 2.2.0 and 2.2.1</para>
<note><para>In CloudStack 4.0.0-incubating only the XenServer hypervisor is supported for use in combination with Nicira NVP</para></note>
<note><para>In CloudStack 4.0.0-incubating the UI components for this plugin are not complete, configuration is done by sending commands to the API</para></note>
<note><para>In CloudStack 4.0.0-incubating only the XenServer hypervisor is supported for use in
combination with Nicira NVP.</para>
<para>In CloudStack 4.1.0-incubating both KVM and XenServer hypervisors are
supported.</para></note>
<note><para>In CloudStack 4.0.0-incubating the UI components for this plugin are not complete,
configuration is done by sending commands to the API.</para></note>
</section>

View File

@ -24,7 +24,9 @@
<title>Prerequisites</title>
<para>Before enabling the Nicira NVP plugin the NVP Controller needs to be configured. Please review the NVP User Guide on how to do that. </para>
<para>CloudStack needs to have at least one physical network with the isolation method set to "STT". This network should be enabled for the Guest traffic type.</para>
<note><para>The Guest traffic type should be configured with the traffic label that matches the name of the Integration Bridge on XenServer. See the Nicira NVP User Guide for more details on how to set this up in XenServer.</para></note>
<note><para>The Guest traffic type should be configured with the traffic label that matches the name of
the Integration Bridge on the hypervisor. See the Nicira NVP User Guide for more details
on how to set this up in XenServer or KVM.</para></note>
<para>Make sure you have the following information ready:</para>
<itemizedlist>
<listitem><para>The IP address of the NVP Controller</para></listitem>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
<!ENTITY % xinclude SYSTEM "http://www.docbook.org/xml/4.4/xinclude.mod">
%xinclude;
]>
<!-- 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.
-->
<section id="plugin-niciranvp-ui">
<title>Configuring the Nicira NVP plugin from the UI</title>
<para>In CloudStack 4.1.0-incubating the Nicira NVP plugin and its resources can be configured in the infrastructure tab of the UI. Navigate to the physical network with STT isolation and configure the network elements. The NiciraNvp is listed here. <!-- TODO add screenshot --></para>
</section>

View File

@ -24,6 +24,7 @@
<title>Using the Nicira NVP Plugin</title>
<xi:include href="plugin-niciranvp-preparations.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
<xi:include href="plugin-niciranvp-ui.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
<xi:include href="plugin-niciranvp-provider.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
<xi:include href="plugin-niciranvp-devicemanagement.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
</chapter>

View File

@ -0,0 +1,75 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent">
%BOOK_ENTITIES;
]>
<!-- 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.
-->
<section id="sys-offering-sysvm">
<title>Changing the Default System Offering for System VMs</title>
<para>You can manually change the system offering for a particular System VM. Additionally, as a
&PRODUCT; administrator, you can also change the default system offering used for System
VMs.</para>
<orderedlist>
<listitem>
<para>Create a new system offering.</para>
<para>For more information, see <phrase condition="install"><xref
linkend="creating-system-service-offerings"/></phrase>
<phrase condition="admin">Creating a New System Service Offering</phrase>. </para>
</listitem>
<listitem>
<para>Back up the database:</para>
<programlisting>mysqldump -u root -p cloud | bzip2 > cloud_backup.sql.bz2</programlisting>
</listitem>
<listitem>
<para>Open an MySQL prompt:</para>
<programlisting>mysql -u cloud -p cloud</programlisting>
</listitem>
<listitem>
<para>Run the following queries on the cloud database.</para>
<orderedlist numeration="loweralpha">
<listitem>
<para>In the disk_offering table, identify the original default offering and the new
offering you want to use by default. </para>
<para>Take a note of the ID of the new offering.</para>
<programlisting>select id,name,unique_name,type from disk_offering;</programlisting>
</listitem>
<listitem>
<para>For the original default offering, set the value of unique_name to NULL.</para>
<programlisting># update disk_offering set unique_name = NULL where id = 10;</programlisting>
<para>Ensure that you use the correct value for the ID.</para>
</listitem>
<listitem>
<para>For the new offering that you want to use by default, set the value of unique_name
as follows:</para>
<para>For the default Console Proxy VM (CPVM) offering,set unique_name to
'Cloud.com-ConsoleProxy'. For the default Secondary Storage VM (SSVM) offering, set
unique_name to 'Cloud.com-SecondaryStorage'. For example:</para>
<programlisting>update disk_offering set unique_name = 'Cloud.com-ConsoleProxy' where id = 16;</programlisting>
</listitem>
</orderedlist>
</listitem>
<listitem>
<para>Restart &PRODUCT; Management Server. Restarting is required because the default
offerings are loaded into the memory at startup.</para>
<programlisting>service cloud-management restart</programlisting>
</listitem>
<listitem>
<para>Destroy the existing CPVM or SSVM offerings and wait for them to be recreated. The new
CPVM or SSVM are configured with the new offering. </para>
</listitem>
</orderedlist>
</section>

View File

@ -20,25 +20,47 @@
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-api-discovery</artifactId>
<name>Apache CloudStack Plugin - API Discovery</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-api-discovery</artifactId>
<name>Apache CloudStack Plugin - API Discovery</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<testResources>
<testResource>
<directory>test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1024m</argLine>
<excludes>
<exclude>org/apache/cloudstack/discovery/integration/*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -57,18 +57,34 @@ public class ApiDiscoveryResponse extends BaseResponse {
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public void setSince(String since) {
this.since = since;
}
public String getSince() {
return since;
}
public void setAsync(Boolean isAsync) {
this.isAsync = isAsync;
}
public boolean getAsync() {
return isAsync;
}
public String getRelated() {
return related;
}

View File

@ -58,18 +58,16 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
if (s_apiNameDiscoveryResponseMap == null) {
long startTime = System.nanoTime();
s_apiNameDiscoveryResponseMap = new HashMap<String, ApiDiscoveryResponse>();
cacheResponseMap();
//TODO: Fix and use PluggableService to get the classes
Set<Class<?>> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class,
new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
cacheResponseMap(cmdClasses);
long endTime = System.nanoTime();
s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms");
}
}
private void cacheResponseMap() {
Set<Class<?>> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class,
new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
//TODO: Fix and use PluggableService to get the classes
protected void cacheResponseMap(Set<Class<?>> cmdClasses) {
Map<String, List<String>> responseApiNameListMap = new HashMap<String, List<String>>();
for (Class<?> cmdClass : cmdClasses) {
@ -109,7 +107,7 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
}
}
Field[] fields = ReflectUtil.getAllFieldsForClass(cmdClass,
Set<Field> fields = ReflectUtil.getAllFieldsForClass(cmdClass,
new Class<?>[]{BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
boolean isAsync = ReflectUtil.isCmdClassAsync(cmdClass,

View File

@ -0,0 +1,87 @@
// 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.discovery;
import com.cloud.user.User;
import com.cloud.user.UserVO;
import com.cloud.utils.component.Adapters;
import java.util.*;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.acl.APIChecker;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.command.user.discovery.ListApisCmd;
import org.apache.cloudstack.api.response.ApiDiscoveryResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class ApiDiscoveryTest {
private static ApiDiscoveryServiceImpl _discoveryService = new ApiDiscoveryServiceImpl();
private static APIChecker _apiChecker = mock(APIChecker.class);
private static Class<?> testCmdClass = ListApisCmd.class;
private static User testUser;
private static String testApiName;
private static String testApiDescription;
private static String testApiSince;
private static boolean testApiAsync;
@BeforeClass
public static void setUp() throws ConfigurationException {
testApiName = testCmdClass.getAnnotation(APICommand.class).name();
testApiDescription = testCmdClass.getAnnotation(APICommand.class).description();
testApiSince = testCmdClass.getAnnotation(APICommand.class).since();
testApiAsync = false;
testUser = new UserVO();
Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
cmdClasses.add(ListApisCmd.class);
_discoveryService.cacheResponseMap(cmdClasses);
_discoveryService.s_apiAccessCheckers = (Adapters<APIChecker>) mock(Adapters.class);
when(_apiChecker.checkAccess(any(User.class), anyString())).thenReturn(true);
when(_discoveryService.s_apiAccessCheckers.iterator()).thenReturn(Arrays.asList(_apiChecker).iterator());
}
@Test
public void verifyListSingleApi() throws Exception {
ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) _discoveryService.listApis(testUser, testApiName);
ApiDiscoveryResponse response = responses.getResponses().get(0);
assertTrue("No. of response items should be one", responses.getCount() == 1);
assertEquals("Error in api name", testApiName, response.getName());
assertEquals("Error in api description", testApiDescription, response.getDescription());
assertEquals("Error in api since", testApiSince, response.getSince());
assertEquals("Error in api isAsync", testApiAsync, response.getAsync());
}
@Test
public void verifyListApis() throws Exception {
ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) _discoveryService.listApis(testUser, null);
assertTrue("No. of response items > 1", responses.getCount() > 1);
for (ApiDiscoveryResponse response: responses.getResponses()) {
assertFalse("API name is empty", response.getName().isEmpty());
assertFalse("API description is empty", response.getDescription().isEmpty());
}
}
}

View File

@ -33,6 +33,7 @@ import org.libvirt.LibvirtException;
import javax.naming.ConfigurationException;
import java.net.URI;
import java.util.Map;
import java.io.File;
public class BridgeVifDriver extends VifDriverBase {
@ -85,6 +86,9 @@ public class BridgeVifDriver extends VifDriverBase {
URI broadcastUri = nic.getBroadcastUri();
vlanId = broadcastUri.getHost();
}
else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver");
}
String trafficLabel = nic.getName();
if (nic.getType() == Networks.TrafficType.Guest) {
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan
@ -172,7 +176,7 @@ public class BridgeVifDriver extends VifDriverBase {
createControlNetwork(_bridges.get("linklocal"));
}
private void deletExitingLinkLocalRoutTable(String linkLocalBr) {
private void deleteExitingLinkLocalRouteTable(String linkLocalBr) {
Script command = new Script("/bin/bash", _timeout);
command.add("-c");
command.add("ip route | grep " + NetUtils.getLinkLocalCIDR());
@ -197,7 +201,7 @@ public class BridgeVifDriver extends VifDriverBase {
}
private void createControlNetwork(String privBrName) {
deletExitingLinkLocalRoutTable(privBrName);
deleteExitingLinkLocalRouteTable(privBrName);
if (!isBridgeExists(privBrName)) {
Script.runSimpleBashScript("brctl addbr " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " +
privBrName + " 169.254.0.1", _timeout);
@ -206,15 +210,11 @@ public class BridgeVifDriver extends VifDriverBase {
}
private boolean isBridgeExists(String bridgeName) {
Script command = new Script("/bin/sh", _timeout);
command.add("-c");
command.add("brctl show|grep " + bridgeName);
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
String result = command.execute(parser);
if (result != null || parser.getLine() == null) {
return false;
} else {
File f = new File("/sys/devices/virtual/net/" + bridgeName);
if (f.exists()) {
return true;
} else {
return false;
}
}
}

View File

@ -365,10 +365,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements
private String _pingTestPath;
private int _dom0MinMem;
protected enum BridgeType {
NATIVE, OPENVSWITCH
}
protected enum defineOps {
UNDEFINE_VM, DEFINE_VM
}
protected BridgeType _bridgeType;
private String getEndIpFromStartIp(String startIp, int numIps) {
String[] tokens = startIp.split("[.]");
@ -477,6 +483,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements
if (storageScriptsDir == null) {
storageScriptsDir = getDefaultStorageScriptsDir();
}
String bridgeType = (String) params.get("network.bridge.type");
if (bridgeType == null) {
_bridgeType = BridgeType.NATIVE;
}
else {
_bridgeType = BridgeType.valueOf(bridgeType.toUpperCase());
}
params.put("domr.scripts.dir", domrScriptsDir);
@ -661,6 +675,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Connect conn = null;
try {
conn = LibvirtConnection.getConnection();
if (_bridgeType == BridgeType.OPENVSWITCH) {
if (conn.getLibVirVersion() < (9 * 1000 + 11)) {
throw new ConfigurationException("LibVirt version 0.9.11 required for openvswitch support, but version "
+ conn.getLibVirVersion() + " detected");
}
}
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.getMessage());
}
@ -706,7 +727,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements
}
}
getPifs();
switch (_bridgeType) {
case OPENVSWITCH:
getOvsPifs();
break;
case NATIVE:
default:
getPifs();
break;
}
if (_pifs.get("private") == null) {
s_logger.debug("Failed to get private nic name");
throw new ConfigurationException("Failed to get private nic name");
@ -765,33 +795,46 @@ public class LibvirtComputingResource extends ServerResourceBase implements
// Load the vif driver
String vifDriverName = (String) params.get("libvirt.vif.driver");
if (vifDriverName == null) {
s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver.");
vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver";
if (_bridgeType == BridgeType.OPENVSWITCH) {
s_logger.info("No libvirt.vif.driver specififed. Defaults to OvsVifDriver.");
vifDriverName = "com.cloud.hypervisor.kvm.resource.OvsVifDriver";
} else {
s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver.");
vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver";
}
}
params.put("libvirt.computing.resource", (Object) this);
try {
Class<?> clazz = Class.forName(vifDriverName);
_vifDriver = (VifDriver) clazz.newInstance();
_vifDriver.configure(params);
Class<?> clazz = Class.forName(vifDriverName);
_vifDriver = (VifDriver) clazz.newInstance();
_vifDriver.configure(params);
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e);
throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e);
} catch (InstantiationException e) {
throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e);
throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e);
} catch (Exception e) {
throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e);
throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e);
}
return true;
}
private void getPifs() {
/* gather all available bridges and find their pifs, so that we can match them against traffic labels later */
String cmdout = Script.runSimpleBashScript("brctl show | tail -n +2 | grep -v \"^\\s\"|awk '{print $1}'|sed '{:q;N;s/\\n/%/g;t q}'");
s_logger.debug("cmdout was " + cmdout);
List<String> bridges = Arrays.asList(cmdout.split("%"));
File dir = new File("/sys/devices/virtual/net");
File[] netdevs = dir.listFiles();
List<String> bridges = new ArrayList<String>();
for (int i = 0; i < netdevs.length; i++) {
File isbridge = new File(netdevs[i].getAbsolutePath() + "/bridge");
String netdevName = netdevs[i].getName();
s_logger.debug("looking in file " + netdevs[i].getAbsolutePath() + "/bridge");
if (isbridge.exists()) {
s_logger.debug("Found bridge " + netdevName);
bridges.add(netdevName);
}
}
for (String bridge : bridges) {
s_logger.debug("looking for pif for bridge " + bridge);
String pif = getPif(bridge);
@ -805,31 +848,115 @@ public class LibvirtComputingResource extends ServerResourceBase implements
}
s_logger.debug("done looking for pifs, no more bridges");
}
private void getOvsPifs() {
String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'");
s_logger.debug("cmdout was " + cmdout);
List<String> bridges = Arrays.asList(cmdout.split("%"));
for (String bridge : bridges) {
s_logger.debug("looking for pif for bridge " + bridge);
// String pif = getOvsPif(bridge);
// Not really interested in the pif name at this point for ovs
// bridges
String pif = bridge;
if (_publicBridgeName != null && bridge.equals(_publicBridgeName)) {
_pifs.put("public", pif);
}
if (_guestBridgeName != null && bridge.equals(_guestBridgeName)) {
_pifs.put("private", pif);
}
_pifs.put(bridge, pif);
}
s_logger.debug("done looking for pifs, no more bridges");
}
private String getPif(String bridge) {
String pif = Script.runSimpleBashScript("brctl show | grep " + bridge + " | awk '{print $4}'");
String vlan = Script.runSimpleBashScript("ls /proc/net/vlan/" + pif);
String pif = matchPifFileInDirectory(bridge);
File vlanfile = new File("/proc/net/vlan" + pif);
if (vlan != null && !vlan.isEmpty()) {
pif = Script.runSimpleBashScript("grep ^Device\\: /proc/net/vlan/" + pif + " | awk {'print $2'}");
if (vlanfile.isFile()) {
pif = Script.runSimpleBashScript("grep ^Device\\: /proc/net/vlan/"
+ pif + " | awk {'print $2'}");
}
return pif;
}
private String getOvsPif(String bridge) {
String pif = Script.runSimpleBashScript("ovs-vsctl list-ports " + bridge);
return pif;
}
private String matchPifFileInDirectory(String bridgeName){
File f = new File("/sys/devices/virtual/net/" + bridgeName + "/brif");
if (! f.isDirectory()){
s_logger.debug("failing to get physical interface from bridge"
+ bridgeName + ", does " + f.getAbsolutePath()
+ "exist?");
return "";
}
File[] interfaces = f.listFiles();
for (int i = 0; i < interfaces.length; i++) {
String fname = interfaces[i].getName();
s_logger.debug("matchPifFileInDirectory: file name '"+fname+"'");
if (fname.startsWith("eth") || fname.startsWith("bond")
|| fname.startsWith("vlan")) {
return fname;
}
}
s_logger.debug("failing to get physical interface from bridge"
+ bridgeName + ", did not find an eth*, bond*, or vlan* in "
+ f.getAbsolutePath());
return "";
}
private boolean checkNetwork(String networkName) {
if (networkName == null) {
return true;
}
String name = Script.runSimpleBashScript("brctl show | grep "
+ networkName + " | awk '{print $4}'");
if (name == null) {
if (_bridgeType == BridgeType.OPENVSWITCH) {
return checkOvsNetwork(networkName);
} else {
return checkBridgeNetwork(networkName);
}
}
private boolean checkBridgeNetwork(String networkName) {
if (networkName == null) {
return true;
}
String name = matchPifFileInDirectory(networkName);
if (name == null || name.isEmpty()) {
return false;
} else {
return true;
}
}
private boolean checkOvsNetwork(String networkName) {
s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge");
if (networkName == null) {
return true;
}
Script command = new Script("/bin/sh", _timeout);
command.add("-c");
command.add("ovs-vsctl br-exists " + networkName);
String result = command.execute(null);
if ("Ok".equals(result)) {
return true;
} else {
return false;
}
}
private String getVnetId(String vnetId) {
return vnetId;
@ -1381,20 +1508,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements
}
private String getVlanIdFromBridge(String brName) {
OutputInterpreter.OneLineParser vlanIdParser = new OutputInterpreter.OneLineParser();
final Script cmd = new Script("/bin/bash", s_logger);
cmd.add("-c");
cmd.add("vlanid=$(brctl show |grep " + brName
+ " |awk '{print $4}' | cut -s -d. -f 2);echo $vlanid");
String result = cmd.execute(vlanIdParser);
if (result != null) {
return null;
}
String vlanId = vlanIdParser.getLine();
if (vlanId.equalsIgnoreCase("")) {
return null;
String pif= matchPifFileInDirectory(brName);
String[] pifparts = pif.split("\\.");
if(pifparts.length == 2) {
return pifparts[1];
} else {
return vlanId;
s_logger.debug("failed to get vlan id from bridge " + brName
+ "attached to physical interface" + pif);
return "";
}
}
@ -1619,20 +1741,17 @@ public class LibvirtComputingResource extends ServerResourceBase implements
String pluggedVlan = pluggedNic.getBrName();
if (pluggedVlan.equalsIgnoreCase(_linkLocalBridgeName)) {
vlanToNicNum.put("LinkLocal",devNum);
}
else if (pluggedVlan.equalsIgnoreCase(_publicBridgeName)
} else if (pluggedVlan.equalsIgnoreCase(_publicBridgeName)
|| pluggedVlan.equalsIgnoreCase(_privBridgeName)
|| pluggedVlan.equalsIgnoreCase(_guestBridgeName)) {
vlanToNicNum.put(Vlan.UNTAGGED,devNum);
}
else {
} else {
vlanToNicNum.put(getVlanIdFromBridge(pluggedVlan),devNum);
}
devNum++;
}
for (IpAddressTO ip : ips) {
String ipVlan = ip.getVlanId();
String nicName = "eth" + vlanToNicNum.get(ip.getVlanId());
String netmask = Long.toString(NetUtils.getCidrSize(ip.getVlanNetmask()));
String subnet = NetUtils.getSubNet(ip.getPublicIp(), ip.getVlanNetmask());

View File

@ -646,6 +646,9 @@ public class LibvirtVMDef {
private String _ipAddr;
private String _scriptPath;
private nicModel _model;
private String _virtualPortType;
private String _virtualPortInterfaceId;
private int _vlanTag = -1;
public void defBridgeNet(String brName, String targetBrName,
String macAddr, nicModel model) {
@ -695,7 +698,31 @@ public class LibvirtVMDef {
public String getMacAddress() {
return _macAddr;
}
public void setVirtualPortType(String virtualPortType) {
_virtualPortType = virtualPortType;
}
public String getVirtualPortType() {
return _virtualPortType;
}
public void setVirtualPortInterfaceId(String virtualPortInterfaceId) {
_virtualPortInterfaceId = virtualPortInterfaceId;
}
public String getVirtualPortInterfaceId() {
return _virtualPortInterfaceId;
}
public void setVlanTag(int vlanTag) {
_vlanTag = vlanTag;
}
public int getVlanTag() {
return _vlanTag;
}
@Override
public String toString() {
StringBuilder netBuilder = new StringBuilder();
@ -714,6 +741,16 @@ public class LibvirtVMDef {
if (_model != null) {
netBuilder.append("<model type='" + _model + "'/>\n");
}
if (_virtualPortType != null) {
netBuilder.append("<virtualport type='" + _virtualPortType + "'>\n");
if (_virtualPortInterfaceId != null) {
netBuilder.append("<parameters interfaceid='" + _virtualPortInterfaceId + "'/>\n");
}
netBuilder.append("</virtualport>\n");
}
if (_vlanTag > 0 && _vlanTag < 4095) {
netBuilder.append("<vlan trunk='no'>\n<tag id='" + _vlanTag + "'/>\n</vlan>");
}
netBuilder.append("</interface>\n");
return netBuilder.toString();
}

View File

@ -0,0 +1,189 @@
/*
* 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.hypervisor.kvm.resource;
import java.net.URI;
import java.util.Map;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.libvirt.LibvirtException;
import com.cloud.agent.api.to.NicTO;
import com.cloud.exception.InternalErrorException;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef;
import com.cloud.network.Networks;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;
public class OvsVifDriver extends VifDriverBase {
private static final Logger s_logger = Logger.getLogger(OvsVifDriver.class);
private int _timeout;
private String _modifyVlanPath;
@Override
public void configure(Map<String, Object> params) throws ConfigurationException {
super.configure(params);
String networkScriptsDir = (String) params.get("network.scripts.dir");
if (networkScriptsDir == null) {
networkScriptsDir = "scripts/vm/network/vnet";
}
String value = (String) params.get("scripts.timeout");
_timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000;
_modifyVlanPath = Script.findScript(networkScriptsDir, "modifyvlan.sh");
if (_modifyVlanPath == null) {
throw new ConfigurationException("Unable to find modifyvlan.sh");
}
createControlNetwork(_bridges.get("linklocal"));
}
@Override
public InterfaceDef plug(NicTO nic, String guestOsType)
throws InternalErrorException, LibvirtException {
s_logger.debug("plugging nic=" + nic);
LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef();
intf.setVirtualPortType("openvswitch");
String vlanId = null;
String logicalSwitchUuid = null;
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) {
URI broadcastUri = nic.getBroadcastUri();
vlanId = broadcastUri.getHost();
}
else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart();
}
String trafficLabel = nic.getName();
if (nic.getType() == Networks.TrafficType.Guest) {
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan
&& !vlanId.equalsIgnoreCase("untagged")) {
if(trafficLabel != null && !trafficLabel.isEmpty()) {
s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel);
intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType));
intf.setVlanTag(Integer.parseInt(vlanId));
} else {
intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType));
intf.setVlanTag(Integer.parseInt(vlanId));
}
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid);
intf.setVirtualPortInterfaceId(nic.getUuid());
String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private");
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType));
}
else {
intf.defBridgeNet(_bridges.get("guest"), null, nic.getMac(), getGuestNicModel(guestOsType));
}
} else if (nic.getType() == Networks.TrafficType.Control) {
/* Make sure the network is still there */
createControlNetwork(_bridges.get("linklocal"));
intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType));
} else if (nic.getType() == Networks.TrafficType.Public) {
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan
&& !vlanId.equalsIgnoreCase("untagged")) {
if(trafficLabel != null && !trafficLabel.isEmpty()){
s_logger.debug("creating a vlan dev and bridge for public traffic per traffic label " + trafficLabel);
intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType));
intf.setVlanTag(Integer.parseInt(vlanId));
} else {
intf.defBridgeNet(_pifs.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType));
intf.setVlanTag(Integer.parseInt(vlanId));
}
} else {
intf.defBridgeNet(_bridges.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType));
}
} else if (nic.getType() == Networks.TrafficType.Management) {
intf.defBridgeNet(_bridges.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType));
} else if (nic.getType() == Networks.TrafficType.Storage) {
String storageBrName = nic.getName() == null ? _bridges.get("private")
: nic.getName();
intf.defBridgeNet(storageBrName, null, nic.getMac(), getGuestNicModel(guestOsType));
}
return intf;
}
@Override
public void unplug(InterfaceDef iface) {
// Libvirt apparently takes care of this, see BridgeVifDriver unplug
}
private String setVnetBrName(String pifName, String vnetId) {
String brName = "br" + pifName + "-"+ vnetId;
String oldStyleBrName = "cloudVirBr" + vnetId;
if (isBridgeExists(oldStyleBrName)) {
s_logger.info("Using old style bridge name for vlan " + vnetId + " because existing bridge " + oldStyleBrName + " was found");
brName = oldStyleBrName;
}
return brName;
}
private void deleteExitingLinkLocalRouteTable(String linkLocalBr) {
Script command = new Script("/bin/bash", _timeout);
command.add("-c");
command.add("ip route | grep " + NetUtils.getLinkLocalCIDR());
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
String result = command.execute(parser);
boolean foundLinkLocalBr = false;
if (result == null && parser.getLines() != null) {
String[] lines = parser.getLines().split("\\n");
for (String line : lines) {
String[] tokens = line.split(" ");
if (!tokens[2].equalsIgnoreCase(linkLocalBr)) {
Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR());
} else {
foundLinkLocalBr = true;
}
}
}
if (!foundLinkLocalBr) {
Script.runSimpleBashScript("ifconfig " + linkLocalBr + " 169.254.0.1;" + "ip route add " +
NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway());
}
}
private void createControlNetwork(String privBrName) {
deleteExitingLinkLocalRouteTable(privBrName);
if (!isBridgeExists(privBrName)) {
Script.runSimpleBashScript("ovs-vsctl add-br " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " +
privBrName + " 169.254.0.1", _timeout);
}
}
private boolean isBridgeExists(String bridgeName) {
Script command = new Script("/bin/sh", _timeout);
command.add("-c");
command.add("ovs-vsctl br-exists " + bridgeName);
String result = command.execute(null);
if ("Ok".equals(result)) {
return true;
} else {
return false;
}
}
}

View File

@ -38,6 +38,10 @@ public class KVMStoragePoolManager {
private final Map<String, StorageAdaptor> _storageMapper = new HashMap<String, StorageAdaptor>();
private StorageAdaptor getStorageAdaptor(StoragePoolType type) {
// type can be null: LibVirtComputingResource:3238
if (type == null) {
return _storageMapper.get("libvirt");
}
StorageAdaptor adaptor = _storageMapper.get(type.toString());
if (adaptor == null) {
// LibvirtStorageAdaptor is selected by default

View File

@ -71,7 +71,7 @@ umount_raw_disk() {
sync
while [ $retry -gt 0 ]
do
umount $path &>/dev/null
umount -d $path &>/dev/null
if [ $? -gt 0 ]
then
sleep 5

View File

@ -105,6 +105,7 @@
<exclude>com/cloud/vm/dao/*</exclude>
<exclude>com/cloud/vpc/*</exclude>
<exclude>com/cloud/api/ListPerfTest.java</exclude>
<exclude>com/cloud/network/vpn/RemoteAccessVpnTest.java</exclude>
</excludes>
</configuration>
</plugin>

View File

@ -26,6 +26,7 @@ import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
@ -35,13 +36,17 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse;
import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import com.cloud.api.query.dao.AccountJoinDao;
import com.cloud.api.query.dao.AsyncJobJoinDao;
import com.cloud.api.query.dao.DataCenterJoinDao;
import com.cloud.api.query.dao.DiskOfferingJoinDao;
import com.cloud.api.query.dao.DomainRouterJoinDao;
import com.cloud.api.query.dao.HostJoinDao;
import com.cloud.api.query.dao.InstanceGroupJoinDao;
@ -50,12 +55,15 @@ import com.cloud.api.query.dao.ProjectInvitationJoinDao;
import com.cloud.api.query.dao.ProjectJoinDao;
import com.cloud.api.query.dao.ResourceTagJoinDao;
import com.cloud.api.query.dao.SecurityGroupJoinDao;
import com.cloud.api.query.dao.ServiceOfferingJoinDao;
import com.cloud.api.query.dao.StoragePoolJoinDao;
import com.cloud.api.query.dao.UserAccountJoinDao;
import com.cloud.api.query.dao.UserVmJoinDao;
import com.cloud.api.query.dao.VolumeJoinDao;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.AsyncJobJoinVO;
import com.cloud.api.query.vo.DataCenterJoinVO;
import com.cloud.api.query.vo.DiskOfferingJoinVO;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.api.query.vo.EventJoinVO;
import com.cloud.api.query.vo.HostJoinVO;
@ -65,6 +73,7 @@ import com.cloud.api.query.vo.ProjectInvitationJoinVO;
import com.cloud.api.query.vo.ProjectJoinVO;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.SecurityGroupJoinVO;
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
import com.cloud.api.query.vo.StoragePoolJoinVO;
import com.cloud.api.query.vo.UserAccountJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
@ -82,6 +91,7 @@ import com.cloud.configuration.Resource.ResourceType;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.AccountVlanMapVO;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.Vlan;
@ -163,6 +173,7 @@ import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.dao.StaticRouteDao;
import com.cloud.network.vpc.dao.VpcGatewayDao;
import com.cloud.network.vpc.dao.VpcOfferingDao;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.NetworkOfferingVO;
@ -333,6 +344,9 @@ public class ApiDBUtils {
private static StoragePoolJoinDao _poolJoinDao;
private static AccountJoinDao _accountJoinDao;
private static AsyncJobJoinDao _jobJoinDao;
private static DiskOfferingJoinDao _diskOfferingJoinDao;
private static ServiceOfferingJoinDao _srvOfferingJoinDao;
private static DataCenterJoinDao _dcJoinDao;
private static PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
private static PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
@ -437,6 +451,9 @@ public class ApiDBUtils {
_vpcOfferingDao = locator.getDao(VpcOfferingDao.class);
_snapshotPolicyDao = locator.getDao(SnapshotPolicyDao.class);
_asyncJobDao = locator.getDao(AsyncJobDao.class);
_diskOfferingJoinDao = locator.getDao(DiskOfferingJoinDao.class);
_srvOfferingJoinDao = locator.getDao(ServiceOfferingJoinDao.class);
_dcJoinDao = locator.getDao(DataCenterJoinDao.class);
// Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
_statsCollector = StatsCollector.getInstance();
@ -1399,4 +1416,28 @@ public class ApiDBUtils {
public static AsyncJobJoinVO newAsyncJobView(AsyncJob e){
return _jobJoinDao.newAsyncJobView(e);
}
public static DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO offering) {
return _diskOfferingJoinDao.newDiskOfferingResponse(offering);
}
public static DiskOfferingJoinVO newDiskOfferingView(DiskOffering offering){
return _diskOfferingJoinDao.newDiskOfferingView(offering);
}
public static ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO offering) {
return _srvOfferingJoinDao.newServiceOfferingResponse(offering);
}
public static ServiceOfferingJoinVO newServiceOfferingView(ServiceOffering offering){
return _srvOfferingJoinDao.newServiceOfferingView(offering);
}
public static ZoneResponse newDataCenterResponse(DataCenterJoinVO dc, Boolean showCapacities) {
return _dcJoinDao.newDataCenterResponse(dc, showCapacities);
}
public static DataCenterJoinVO newDataCenterView(DataCenter dc){
return _dcJoinDao.newDataCenterView(dc);
}
}

View File

@ -27,6 +27,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
@ -157,8 +158,7 @@ public class ApiDispatcher {
}
if (queueSizeLimit != null) {
_asyncMgr
.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit);
_asyncMgr.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit);
} else {
s_logger.trace("The queue size is unlimited, skipping the synchronizing");
}
@ -190,8 +190,7 @@ public class ApiDispatcher {
}
}
Field[] fields = ReflectUtil.getAllFieldsForClass(cmd.getClass(),
new Class<?>[] {BaseCmd.class});
List<Field> fields = ReflectUtil.getAllFieldsForClass(cmd.getClass(), BaseCmd.class);
for (Field field : fields) {
PlugService plugServiceAnnotation = field.getAnnotation(PlugService.class);
@ -360,8 +359,9 @@ public class ApiDispatcher {
// Go through each entity which is an interface to a VO class and get a VO object
// Try to getId() for the object using reflection, break on first non-null value
for (Class<?> entity: entities) {
// findByUuid returns one VO object using uuid, use reflect to get the Id
Object objVO = s_instance._entityMgr.findByUuid(entity, uuid);
// For backward compatibility, we search within removed entities and let service layer deal
// with removed ones, return empty response or error
Object objVO = s_instance._entityMgr.findByUuidIncludingRemoved(entity, uuid);
if (objVO == null) {
continue;
}
@ -377,11 +377,10 @@ public class ApiDispatcher {
break;
}
if (internalId == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Object entity with uuid=" + uuid + " does not exist in the database.");
}
if (s_logger.isDebugEnabled())
s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
throw new InvalidParameterValueException("Invalid parameter value=" + uuid
+ " due to incorrect long value, entity not found, or an annotation bug.");
+ " due to incorrect long value format, or entity was not found as it may have been deleted, or due to incorrect parameter annotation for the field in api cmd.");
}
return internalId;
}

View File

@ -44,6 +44,8 @@ import com.cloud.api.query.ViewResponseHelper;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.AsyncJobJoinVO;
import com.cloud.api.query.vo.ControlledViewEntity;
import com.cloud.api.query.vo.DataCenterJoinVO;
import com.cloud.api.query.vo.DiskOfferingJoinVO;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.api.query.vo.EventJoinVO;
import com.cloud.api.query.vo.HostJoinVO;
@ -53,6 +55,7 @@ import com.cloud.api.query.vo.ProjectInvitationJoinVO;
import com.cloud.api.query.vo.ProjectJoinVO;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.SecurityGroupJoinVO;
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
import com.cloud.api.query.vo.StoragePoolJoinVO;
import com.cloud.api.query.vo.UserAccountJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
@ -298,24 +301,8 @@ public class ApiResponseHelper implements ResponseGenerator {
@Override
public DiskOfferingResponse createDiskOfferingResponse(DiskOffering offering) {
DiskOfferingResponse diskOfferingResponse = new DiskOfferingResponse();
diskOfferingResponse.setId(offering.getUuid());
diskOfferingResponse.setName(offering.getName());
diskOfferingResponse.setDisplayText(offering.getDisplayText());
diskOfferingResponse.setCreated(offering.getCreated());
diskOfferingResponse.setDiskSize(offering.getDiskSize() / (1024 * 1024 * 1024));
if (offering.getDomainId() != null) {
Domain domain = ApiDBUtils.findDomainById(offering.getDomainId());
if (domain != null) {
diskOfferingResponse.setDomain(domain.getName());
diskOfferingResponse.setDomainId(domain.getUuid());
}
}
diskOfferingResponse.setTags(offering.getTags());
diskOfferingResponse.setCustomized(offering.isCustomized());
diskOfferingResponse.setStorageType(offering.getUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
diskOfferingResponse.setObjectName("diskoffering");
return diskOfferingResponse;
DiskOfferingJoinVO vOffering = ApiDBUtils.newDiskOfferingView(offering);
return ApiDBUtils.newDiskOfferingResponse(vOffering);
}
@Override
@ -357,33 +344,8 @@ public class ApiResponseHelper implements ResponseGenerator {
@Override
public ServiceOfferingResponse createServiceOfferingResponse(ServiceOffering offering) {
ServiceOfferingResponse offeringResponse = new ServiceOfferingResponse();
offeringResponse.setId(offering.getUuid());
offeringResponse.setName(offering.getName());
offeringResponse.setIsSystemOffering(offering.getSystemUse());
offeringResponse.setDefaultUse(offering.getDefaultUse());
offeringResponse.setSystemVmType(offering.getSystemVmType());
offeringResponse.setDisplayText(offering.getDisplayText());
offeringResponse.setCpuNumber(offering.getCpu());
offeringResponse.setCpuSpeed(offering.getSpeed());
offeringResponse.setMemory(offering.getRamSize());
offeringResponse.setCreated(offering.getCreated());
offeringResponse.setStorageType(offering.getUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
offeringResponse.setOfferHa(offering.getOfferHA());
offeringResponse.setLimitCpuUse(offering.getLimitCpuUse());
offeringResponse.setTags(offering.getTags());
if (offering.getDomainId() != null) {
Domain domain = ApiDBUtils.findDomainById(offering.getDomainId());
if (domain != null) {
offeringResponse.setDomain(domain.getName());
offeringResponse.setDomainId(domain.getUuid());
}
}
offeringResponse.setNetworkRate(offering.getRateMbps());
offeringResponse.setHostTag(offering.getHostTag());
offeringResponse.setObjectName("serviceoffering");
return offeringResponse;
ServiceOfferingJoinVO vOffering = ApiDBUtils.newServiceOfferingView(offering);
return ApiDBUtils.newServiceOfferingResponse(vOffering);
}
@Override
@ -756,77 +718,42 @@ public class ApiResponseHelper implements ResponseGenerator {
@Override
public ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapacities) {
Account account = UserContext.current().getCaller();
ZoneResponse zoneResponse = new ZoneResponse();
zoneResponse.setId(dataCenter.getUuid());
zoneResponse.setName(dataCenter.getName());
zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId()));
zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled());
if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
zoneResponse.setDescription(dataCenter.getDescription());
}
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
zoneResponse.setDns1(dataCenter.getDns1());
zoneResponse.setDns2(dataCenter.getDns2());
zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
// FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
}
if (showCapacities != null && showCapacities) {
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(dataCenter.getId(), null, null);
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
for (SummedCapacity capacity : capacities) {
CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor)));
} else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(dataCenter.getId(), null, null);
capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
} else {
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
}
if (capacityResponse.getCapacityTotal() != 0) {
capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
} else {
capacityResponse.setPercentUsed(s_percentFormat.format(0L));
}
capacityResponses.add(capacityResponse);
}
// Do it for stats as well.
capacityResponses.addAll(getStatsCapacityresponse(null, null, null, dataCenter.getId()));
zoneResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
}
// set network domain info
zoneResponse.setDomain(dataCenter.getDomain());
// set domain info
Long domainId = dataCenter.getDomainId();
if (domainId != null) {
Domain domain = ApiDBUtils.findDomainById(domainId);
zoneResponse.setDomainId(domain.getId());
zoneResponse.setDomainName(domain.getName());
}
zoneResponse.setType(dataCenter.getNetworkType().toString());
zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
zoneResponse.setZoneToken(dataCenter.getZoneToken());
zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
zoneResponse.setObjectName("zone");
return zoneResponse;
DataCenterJoinVO vOffering = ApiDBUtils.newDataCenterView(dataCenter);
return ApiDBUtils.newDataCenterResponse(vOffering, showCapacities);
}
private List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) {
public static List<CapacityResponse> getDataCenterCapacityResponse(Long zoneId){
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(zoneId, null, null);
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
for (SummedCapacity capacity : capacities) {
CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor)));
} else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(zoneId, null, null);
capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
} else {
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
}
if (capacityResponse.getCapacityTotal() != 0) {
capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
} else {
capacityResponse.setPercentUsed(s_percentFormat.format(0L));
}
capacityResponses.add(capacityResponse);
}
// Do it for stats as well.
capacityResponses.addAll(getStatsCapacityresponse(null, null, null, zoneId));
return new ArrayList<CapacityResponse>(capacityResponses);
}
private static List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) {
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId));
if (clusterId == null && podId == null) {

View File

@ -61,6 +61,7 @@ import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.ConnectionClosedException;
@ -95,6 +96,8 @@ import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
@ -514,6 +517,9 @@ public class ApiServer implements HttpRequestHandler {
&& !(cmdObj instanceof ListUsersCmd)
&& !(cmdObj instanceof ListAccountsCmd)
&& !(cmdObj instanceof ListStoragePoolsCmd)
&& !(cmdObj instanceof ListDiskOfferingsCmd)
&& !(cmdObj instanceof ListServiceOfferingsCmd)
&& !(cmdObj instanceof ListZonesByCmd)
) {
buildAsyncListResponse((BaseListCmd) cmdObj, caller);
}

View File

@ -28,6 +28,7 @@ import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import com.cloud.utils.IteratorUtil;
import com.cloud.utils.ReflectUtil;
import org.apache.cloudstack.api.*;
import org.apache.log4j.Logger;
@ -135,7 +136,7 @@ public class ApiXmlDocWriter {
String commandRoleMask = preProcessedCommand.substring(splitIndex + 1);
Class<?> cmdClass = _apiNameCmdClassMap.get(key);
if (cmdClass == null) {
System.out.println("Check, Null Value for key: " + key + " preProcessedCommand=" + preProcessedCommand);
System.out.println("Check, is this api part of another build profile? Null value for key: " + key + " preProcessedCommand=" + preProcessedCommand);
continue;
}
String commandName = cmdClass.getName();
@ -349,7 +350,7 @@ public class ApiXmlDocWriter {
apiCommand.setAsync(isAsync);
Field[] fields = ReflectUtil.getAllFieldsForClass(clas,
Set<Field> fields = ReflectUtil.getAllFieldsForClass(clas,
new Class<?>[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
request = setRequestFields(fields);
@ -422,10 +423,10 @@ public class ApiXmlDocWriter {
out.writeObject(apiCommand);
}
private static ArrayList<Argument> setRequestFields(Field[] fields) {
private static ArrayList<Argument> setRequestFields(Set<Field> fields) {
ArrayList<Argument> arguments = new ArrayList<Argument>();
ArrayList<Argument> requiredArguments = new ArrayList<Argument>();
ArrayList<Argument> optionalArguments = new ArrayList<Argument>();
Set<Argument> requiredArguments = new HashSet<Argument>();
Set<Argument> optionalArguments = new HashSet<Argument>();
Argument id = null;
for (Field f : fields) {
Parameter parameterAnnotation = f.getAnnotation(Parameter.class);
@ -444,7 +445,7 @@ public class ApiXmlDocWriter {
reqArg.setSinceVersion(parameterAnnotation.since());
}
if (reqArg.isRequired() == true) {
if (reqArg.isRequired()) {
if (parameterAnnotation.name().equals("id")) {
id = reqArg;
} else {
@ -456,15 +457,12 @@ public class ApiXmlDocWriter {
}
}
Collections.sort(requiredArguments);
Collections.sort(optionalArguments);
// sort required and optional arguments here
if (id != null) {
arguments.add(id);
}
arguments.addAll(requiredArguments);
arguments.addAll(optionalArguments);
arguments.addAll(IteratorUtil.asSortedList(requiredArguments));
arguments.addAll(IteratorUtil.asSortedList(optionalArguments));
return arguments;
}

View File

@ -18,8 +18,11 @@ package com.cloud.api.query;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
@ -32,6 +35,8 @@ import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd;
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
@ -39,8 +44,10 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
@ -51,15 +58,19 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse;
import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.query.QueryService;
import org.apache.log4j.Logger;
import com.cloud.api.query.dao.AccountJoinDao;
import com.cloud.api.query.dao.AsyncJobJoinDao;
import com.cloud.api.query.dao.DataCenterJoinDao;
import com.cloud.api.query.dao.DiskOfferingJoinDao;
import com.cloud.api.query.dao.DomainRouterJoinDao;
import com.cloud.api.query.dao.HostJoinDao;
import com.cloud.api.query.dao.InstanceGroupJoinDao;
@ -68,12 +79,15 @@ import com.cloud.api.query.dao.ProjectInvitationJoinDao;
import com.cloud.api.query.dao.ProjectJoinDao;
import com.cloud.api.query.dao.ResourceTagJoinDao;
import com.cloud.api.query.dao.SecurityGroupJoinDao;
import com.cloud.api.query.dao.ServiceOfferingJoinDao;
import com.cloud.api.query.dao.StoragePoolJoinDao;
import com.cloud.api.query.dao.UserAccountJoinDao;
import com.cloud.api.query.dao.UserVmJoinDao;
import com.cloud.api.query.dao.VolumeJoinDao;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.AsyncJobJoinVO;
import com.cloud.api.query.vo.DataCenterJoinVO;
import com.cloud.api.query.vo.DiskOfferingJoinVO;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.api.query.vo.EventJoinVO;
import com.cloud.api.query.vo.HostJoinVO;
@ -83,20 +97,25 @@ import com.cloud.api.query.vo.ProjectInvitationJoinVO;
import com.cloud.api.query.vo.ProjectJoinVO;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.SecurityGroupJoinVO;
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
import com.cloud.api.query.vo.StoragePoolJoinVO;
import com.cloud.api.query.vo.UserAccountJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
import com.cloud.api.query.vo.VolumeJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenterVO;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.dao.EventJoinDao;
import com.cloud.exception.CloudAuthenticationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.security.SecurityGroupVMMapVO;
import com.cloud.network.security.dao.SecurityGroupVMMapDao;
import com.cloud.org.Grouping;
import com.cloud.projects.ProjectInvitation;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.projects.Project;
@ -104,6 +123,9 @@ import com.cloud.projects.ProjectManager;
import com.cloud.projects.dao.ProjectAccountDao;
import com.cloud.projects.dao.ProjectDao;
import com.cloud.server.Criteria;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.StoragePool;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.Volume;
@ -122,8 +144,10 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
/**
@ -199,6 +223,9 @@ public class QueryManagerImpl implements QueryService, Manager {
@Inject
private AccountDao _accountDao;
@Inject
private ConfigurationDao _configDao;
@Inject
private AccountJoinDao _accountJoinDao;
@ -208,6 +235,21 @@ public class QueryManagerImpl implements QueryService, Manager {
@Inject
private StoragePoolJoinDao _poolJoinDao;
@Inject
private DiskOfferingJoinDao _diskOfferingJoinDao;
@Inject
private ServiceOfferingJoinDao _srvOfferingJoinDao;
@Inject
private ServiceOfferingDao _srvOfferingDao;
@Inject
private DataCenterJoinDao _dcJoinDao;
@Inject
private DomainRouterDao _routerDao;
@Inject
private HighAvailabilityManager _haMgr;
@ -1603,7 +1645,7 @@ public class QueryManagerImpl implements QueryService, Manager {
}
public Pair<List<AccountJoinVO>, Integer> searchForAccountsInternal(ListAccountsCmd cmd) {
private Pair<List<AccountJoinVO>, Integer> searchForAccountsInternal(ListAccountsCmd cmd) {
Account caller = UserContext.current().getCaller();
Long domainId = cmd.getDomainId();
Long accountId = cmd.getId();
@ -1729,7 +1771,7 @@ public class QueryManagerImpl implements QueryService, Manager {
}
public Pair<List<AsyncJobJoinVO>, Integer> searchForAsyncJobsInternal(ListAsyncJobsCmd cmd) {
private Pair<List<AsyncJobJoinVO>, Integer> searchForAsyncJobsInternal(ListAsyncJobsCmd cmd) {
Account caller = UserContext.current().getCaller();
@ -1808,7 +1850,7 @@ public class QueryManagerImpl implements QueryService, Manager {
return response;
}
public Pair<List<StoragePoolJoinVO>, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) {
private Pair<List<StoragePoolJoinVO>, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) {
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId());
Object id = cmd.getId();
@ -1888,5 +1930,426 @@ public class QueryManagerImpl implements QueryService, Manager {
}
@Override
public ListResponse<DiskOfferingResponse> searchForDiskOfferings(ListDiskOfferingsCmd cmd) {
Pair<List<DiskOfferingJoinVO>, Integer> result = searchForDiskOfferingsInternal(cmd);
ListResponse<DiskOfferingResponse> response = new ListResponse<DiskOfferingResponse>();
List<DiskOfferingResponse> offeringResponses = ViewResponseHelper.createDiskOfferingResponse(result.first().toArray(new DiskOfferingJoinVO[result.first().size()]));
response.setResponses(offeringResponses, result.second());
return response;
}
private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(ListDiskOfferingsCmd cmd) {
// Note
// The list method for offerings is being modified in accordance with
// discussion with Will/Kevin
// For now, we will be listing the following based on the usertype
// 1. For root, we will list all offerings
// 2. For domainAdmin and regular users, we will list everything in
// their domains+parent domains ... all the way
// till
// root
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = (isAscending == null ? true : isAscending);
Filter searchFilter = new Filter(DiskOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<DiskOfferingJoinVO> sb = _diskOfferingJoinDao.createSearchBuilder();
Account account = UserContext.current().getCaller();
Object name = cmd.getDiskOfferingName();
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long domainId = cmd.getDomainId();
// Keeping this logic consistent with domain specific zones
// if a domainId is provided, we just return the disk offering
// associated with this domain
if (domainId != null) {
if (account.getType() == Account.ACCOUNT_TYPE_ADMIN || isPermissible(account.getDomainId(), domainId) ) {
// check if the user's domain == do's domain || user's domain is
// a child of so's domain for non-root users
sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
SearchCriteria<DiskOfferingJoinVO> sc = sb.create();
sc.setParameters("domainId", domainId);
return _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
} else {
throw new PermissionDeniedException("The account:" + account.getAccountName()
+ " does not fall in the same domain hierarchy as the disk offering");
}
}
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
boolean includePublicOfferings = false;
List<Long> domainIds = null;
// For non-root users, only return all offerings for the user's domain, and everything above till root
if ((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
|| account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
// find all domain Id up to root domain for this account
domainIds = new ArrayList<Long>();
DomainVO domainRecord = _domainDao.findById(account.getDomainId());
if ( domainRecord == null ){
s_logger.error("Could not find the domainId for account:" + account.getAccountName());
throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName());
}
domainIds.add(domainRecord.getId());
while (domainRecord.getParent() != null ){
domainRecord = _domainDao.findById(domainRecord.getParent());
domainIds.add(domainRecord.getId());
}
sb.and("domainIdIn", sb.entity().getDomainId(), SearchCriteria.Op.IN);
// include also public offering if no keyword, name and id specified
if ( keyword == null && name == null && id == null ){
includePublicOfferings = true;
}
}
SearchCriteria<DiskOfferingJoinVO> sc = sb.create();
if (keyword != null) {
SearchCriteria<DiskOfferingJoinVO> ssc = _diskOfferingJoinDao.createSearchCriteria();
ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (name != null) {
sc.setParameters("name", "%" + name + "%");
}
if (id != null) {
sc.setParameters("id", id);
}
if (domainIds != null ){
sc.setParameters("domainIdIn", domainIds);
}
if (includePublicOfferings){
SearchCriteria<DiskOfferingJoinVO> spc = _diskOfferingJoinDao.createSearchCriteria();
spc.addAnd("domainId", SearchCriteria.Op.NULL);
spc.addAnd("systemUse", SearchCriteria.Op.EQ, false);
sc.addOr("systemUse", SearchCriteria.Op.SC, spc);
}
// FIXME: disk offerings should search back up the hierarchy for
// available disk offerings...
/*
* sb.addAnd("domainId", sb.entity().getDomainId(),
* SearchCriteria.Op.EQ); if (domainId != null) {
* SearchBuilder<DomainVO> domainSearch =
* _domainDao.createSearchBuilder(); domainSearch.addAnd("path",
* domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
* sb.join("domainSearch", domainSearch, sb.entity().getDomainId(),
* domainSearch.entity().getId()); }
*/
// FIXME: disk offerings should search back up the hierarchy for
// available disk offerings...
/*
* if (domainId != null) { sc.setParameters("domainId", domainId); //
* //DomainVO domain = _domainDao.findById((Long)domainId); // // I want
* to join on user_vm.domain_id = domain.id where domain.path like
* 'foo%' //sc.setJoinParameters("domainSearch", "path",
* domain.getPath() + "%"); // }
*/
return _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
}
@Override
public ListResponse<ServiceOfferingResponse> searchForServiceOfferings(ListServiceOfferingsCmd cmd) {
Pair<List<ServiceOfferingJoinVO>, Integer> result = searchForServiceOfferingsInternal(cmd);
ListResponse<ServiceOfferingResponse> response = new ListResponse<ServiceOfferingResponse>();
List<ServiceOfferingResponse> offeringResponses = ViewResponseHelper.createServiceOfferingResponse(result.first().toArray(new ServiceOfferingJoinVO[result.first().size()]));
response.setResponses(offeringResponses, result.second());
return response;
}
private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInternal(ListServiceOfferingsCmd cmd) {
// Note
// The list method for offerings is being modified in accordance with
// discussion with Will/Kevin
// For now, we will be listing the following based on the usertype
// 1. For root, we will list all offerings
// 2. For domainAdmin and regular users, we will list everything in
// their domains+parent domains ... all the way
// till
// root
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = (isAscending == null ? true : isAscending);
Filter searchFilter = new Filter(ServiceOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchCriteria<ServiceOfferingJoinVO> sc = _srvOfferingJoinDao.createSearchCriteria();
Account caller = UserContext.current().getCaller();
Object name = cmd.getServiceOfferingName();
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long vmId = cmd.getVirtualMachineId();
Long domainId = cmd.getDomainId();
Boolean isSystem = cmd.getIsSystem();
String vmTypeStr = cmd.getSystemVmType();
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && isSystem) {
throw new InvalidParameterValueException("Only ROOT admins can access system's offering");
}
// Keeping this logic consistent with domain specific zones
// if a domainId is provided, we just return the so associated with this
// domain
if (domainId != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
// check if the user's domain == so's domain || user's domain is a
// child of so's domain
if (!isPermissible(caller.getDomainId(), domainId)) {
throw new PermissionDeniedException("The account:" + caller.getAccountName()
+ " does not fall in the same domain hierarchy as the service offering");
}
}
boolean includePublicOfferings = false;
if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
|| caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
// For non-root users
if (isSystem) {
throw new InvalidParameterValueException("Only root admins can access system's offering");
}
// find all domain Id up to root domain for this account
List<Long> domainIds = new ArrayList<Long>();
DomainVO domainRecord = _domainDao.findById(caller.getDomainId());
if ( domainRecord == null ){
s_logger.error("Could not find the domainId for account:" + caller.getAccountName());
throw new CloudAuthenticationException("Could not find the domainId for account:" + caller.getAccountName());
}
domainIds.add(domainRecord.getId());
while (domainRecord.getParent() != null ){
domainRecord = _domainDao.findById(domainRecord.getParent());
domainIds.add(domainRecord.getId());
}
sc.addAnd("domainId", SearchCriteria.Op.IN, domainIds);
// include also public offering if no keyword, name and id specified
if ( keyword == null && name == null && id == null ){
includePublicOfferings = true;
}
}
else {
// for root users
if (caller.getDomainId() != 1 && isSystem) { // NON ROOT admin
throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering");
}
if (domainId != null) {
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
}
}
if (keyword != null) {
SearchCriteria<ServiceOfferingJoinVO> ssc = _srvOfferingJoinDao.createSearchCriteria();
ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
} else if (vmId != null) {
UserVmVO vmInstance = _userVmDao.findById(vmId);
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id");
ex.addProxyObject(vmInstance, vmId, "vmId");
throw ex;
}
_accountMgr.checkAccess(caller, null, true, vmInstance);
ServiceOfferingVO offering = _srvOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId());
// Only return offerings with the same Guest IP type and storage
// pool preference
// sc.addAnd("guestIpType", SearchCriteria.Op.EQ,
// offering.getGuestIpType());
sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage());
}
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
}
if (isSystem != null) {
sc.addAnd("systemUse", SearchCriteria.Op.EQ, isSystem);
}
if (name != null) {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
}
if (vmTypeStr != null) {
sc.addAnd("vm_type", SearchCriteria.Op.EQ, vmTypeStr);
}
if (includePublicOfferings){
SearchCriteria<ServiceOfferingJoinVO> spc = _srvOfferingJoinDao.createSearchCriteria();
spc.addAnd("domainId", SearchCriteria.Op.NULL);
spc.addAnd("systemUse", SearchCriteria.Op.EQ, false);
sc.addOr("systemUse", SearchCriteria.Op.SC, spc);
}
return _srvOfferingJoinDao.searchAndCount(sc, searchFilter);
}
@Override
public ListResponse<ZoneResponse> listDataCenters(ListZonesByCmd cmd) {
Pair<List<DataCenterJoinVO>, Integer> result = listDataCentersInternal(cmd);
ListResponse<ZoneResponse> response = new ListResponse<ZoneResponse>();
List<ZoneResponse> dcResponses = ViewResponseHelper.createDataCenterResponse(cmd.getShowCapacities(), result.first().toArray(new DataCenterJoinVO[result.first().size()]));
response.setResponses(dcResponses, result.second());
return response;
}
private Pair<List<DataCenterJoinVO>, Integer> listDataCentersInternal(ListZonesByCmd cmd) {
Account account = UserContext.current().getCaller();
Long domainId = cmd.getDomainId();
Long id = cmd.getId();
String keyword = cmd.getKeyword();
Filter searchFilter = new Filter(DataCenterJoinVO.class, null, false, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchCriteria<DataCenterJoinVO> sc = _dcJoinDao.createSearchCriteria();
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
} else {
if (keyword != null) {
SearchCriteria<DataCenterJoinVO> ssc = _dcJoinDao.createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (domainId != null) {
// for domainId != null
// right now, we made the decision to only list zones associated
// with this domain, private zone
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
} else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) {
// it was decided to return all zones for the user's domain, and
// everything above till root
// list all zones belonging to this domain, and all of its
// parents
// check the parent, if not null, add zones for that parent to
// list
// find all domain Id up to root domain for this account
List<Long> domainIds = new ArrayList<Long>();
DomainVO domainRecord = _domainDao.findById(account.getDomainId());
if ( domainRecord == null ){
s_logger.error("Could not find the domainId for account:" + account.getAccountName());
throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName());
}
domainIds.add(domainRecord.getId());
while (domainRecord.getParent() != null ){
domainRecord = _domainDao.findById(domainRecord.getParent());
domainIds.add(domainRecord.getId());
}
// domainId == null (public zones) or domainId IN [all domain id up to root domain]
SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds);
sdc.addOr("domainId", SearchCriteria.Op.NULL);
sc.addAnd("domain", SearchCriteria.Op.SC, sdc);
// remove disabled zones
sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled);
} else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
// it was decided to return all zones for the domain admin, and
// everything above till root, as well as zones till the domain leaf
List<Long> domainIds = new ArrayList<Long>();
DomainVO domainRecord = _domainDao.findById(account.getDomainId());
if ( domainRecord == null ){
s_logger.error("Could not find the domainId for account:" + account.getAccountName());
throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName());
}
domainIds.add(domainRecord.getId());
// find all domain Ids till leaf
List<DomainVO> allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId());
for (DomainVO domain : allChildDomains) {
domainIds.add(domain.getId());
}
// then find all domain Id up to root domain for this account
while (domainRecord.getParent() != null ){
domainRecord = _domainDao.findById(domainRecord.getParent());
domainIds.add(domainRecord.getId());
}
// domainId == null (public zones) or domainId IN [all domain id up to root domain]
SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds);
sdc.addOr("domainId", SearchCriteria.Op.NULL);
sc.addAnd("domain", SearchCriteria.Op.SC, sdc);
// remove disabled zones
sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled);
}
// handle available=FALSE option, only return zones with at least one VM running there
Boolean available = cmd.isAvailable();
if (account != null) {
if ((available != null) && Boolean.FALSE.equals(available)) {
Set<Long> dcIds = new HashSet<Long>(); //data centers with at least one VM running
List<DomainRouterVO> routers = _routerDao.listBy(account.getId());
for (DomainRouterVO router : routers){
dcIds.add(router.getDataCenterIdToDeployIn());
}
if ( dcIds.size() == 0) {
return new Pair<List<DataCenterJoinVO>, Integer>(new ArrayList<DataCenterJoinVO>(), 0);
}
else{
sc.addAnd("idIn", SearchCriteria.Op.IN, dcIds);
}
}
}
}
return _dcJoinDao.searchAndCount(sc, searchFilter);
}
// This method is used for permissions check for both disk and service
// offerings
private boolean isPermissible(Long accountDomainId, Long offeringDomainId) {
if (accountDomainId == offeringDomainId) {
return true; // account and service offering in same domain
}
DomainVO domainRecord = _domainDao.findById(accountDomainId);
if (domainRecord != null) {
while (true) {
if (domainRecord.getId() == offeringDomainId) {
return true;
}
// try and move on to the next domain
if (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
} else {
break;
}
}
}
return false;
}
}

View File

@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
@ -34,15 +35,19 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse;
import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.AsyncJobJoinVO;
import com.cloud.api.query.vo.DataCenterJoinVO;
import com.cloud.api.query.vo.DiskOfferingJoinVO;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.api.query.vo.EventJoinVO;
import com.cloud.api.query.vo.HostJoinVO;
@ -52,6 +57,7 @@ import com.cloud.api.query.vo.ProjectInvitationJoinVO;
import com.cloud.api.query.vo.ProjectJoinVO;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.SecurityGroupJoinVO;
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
import com.cloud.api.query.vo.StoragePoolJoinVO;
import com.cloud.api.query.vo.UserAccountJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
@ -274,4 +280,28 @@ public class ViewResponseHelper {
}
return respList;
}
public static List<DiskOfferingResponse> createDiskOfferingResponse(DiskOfferingJoinVO... offerings) {
List<DiskOfferingResponse> respList = new ArrayList<DiskOfferingResponse>();
for (DiskOfferingJoinVO vt : offerings){
respList.add(ApiDBUtils.newDiskOfferingResponse(vt));
}
return respList;
}
public static List<ServiceOfferingResponse> createServiceOfferingResponse(ServiceOfferingJoinVO... offerings) {
List<ServiceOfferingResponse> respList = new ArrayList<ServiceOfferingResponse>();
for (ServiceOfferingJoinVO vt : offerings){
respList.add(ApiDBUtils.newServiceOfferingResponse(vt));
}
return respList;
}
public static List<ZoneResponse> createDataCenterResponse(Boolean showCapacities, DataCenterJoinVO... dcs) {
List<ZoneResponse> respList = new ArrayList<ZoneResponse>();
for (DataCenterJoinVO vt : dcs){
respList.add(ApiDBUtils.newDataCenterResponse(vt, showCapacities));
}
return respList;
}
}

View File

@ -0,0 +1,30 @@
// 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.query.dao;
import org.apache.cloudstack.api.response.ZoneResponse;
import com.cloud.api.query.vo.DataCenterJoinVO;
import com.cloud.dc.DataCenter;
import com.cloud.utils.db.GenericDao;
public interface DataCenterJoinDao extends GenericDao<DataCenterJoinVO, Long> {
ZoneResponse newDataCenterResponse(DataCenterJoinVO dof, Boolean showCapacities);
DataCenterJoinVO newDataCenterView(DataCenter dof);
}

View File

@ -0,0 +1,109 @@
// 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.query.dao;
import java.util.List;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.vo.DataCenterJoinVO;
import com.cloud.dc.DataCenter;
import org.apache.cloudstack.api.response.ZoneResponse;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value={DataCenterJoinDao.class})
public class DataCenterJoinDaoImpl extends GenericDaoBase<DataCenterJoinVO, Long> implements DataCenterJoinDao {
public static final Logger s_logger = Logger.getLogger(DataCenterJoinDaoImpl.class);
private SearchBuilder<DataCenterJoinVO> dofIdSearch;
protected DataCenterJoinDaoImpl() {
dofIdSearch = createSearchBuilder();
dofIdSearch.and("id", dofIdSearch.entity().getId(), SearchCriteria.Op.EQ);
dofIdSearch.done();
this._count = "select count(distinct id) from data_center_view WHERE ";
}
@Override
public ZoneResponse newDataCenterResponse(DataCenterJoinVO dataCenter, Boolean showCapacities) {
Account account = UserContext.current().getCaller();
ZoneResponse zoneResponse = new ZoneResponse();
zoneResponse.setId(dataCenter.getUuid());
zoneResponse.setName(dataCenter.getName());
zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId()));
zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled());
if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
zoneResponse.setDescription(dataCenter.getDescription());
}
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
zoneResponse.setDns1(dataCenter.getDns1());
zoneResponse.setDns2(dataCenter.getDns2());
zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
// FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
}
if (showCapacities != null && showCapacities) {
zoneResponse.setCapacitites(ApiResponseHelper.getDataCenterCapacityResponse(dataCenter.getId()));
}
// set network domain info
zoneResponse.setDomain(dataCenter.getDomain());
// set domain info
zoneResponse.setDomainId(dataCenter.getDomainUuid());
zoneResponse.setDomainName(dataCenter.getDomainName());
zoneResponse.setType(dataCenter.getNetworkType().toString());
zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
zoneResponse.setZoneToken(dataCenter.getZoneToken());
zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
zoneResponse.setObjectName("zone");
return zoneResponse;
}
@Override
public DataCenterJoinVO newDataCenterView(DataCenter dataCenter) {
SearchCriteria<DataCenterJoinVO> sc = dofIdSearch.create();
sc.setParameters("id", dataCenter.getId());
List<DataCenterJoinVO> dcs = searchIncludingRemoved(sc, null, null, false);
assert dcs != null && dcs.size() == 1 : "No data center found for data center id " + dataCenter.getId();
return dcs.get(0);
}
}

View File

@ -0,0 +1,29 @@
// 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.query.dao;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import com.cloud.api.query.vo.DiskOfferingJoinVO;
import com.cloud.offering.DiskOffering;
import com.cloud.utils.db.GenericDao;
public interface DiskOfferingJoinDao extends GenericDao<DiskOfferingJoinVO, Long> {
DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO dof);
DiskOfferingJoinVO newDiskOfferingView(DiskOffering dof);
}

View File

@ -0,0 +1,101 @@
// 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.query.dao;
import java.util.List;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.api.query.vo.DiskOfferingJoinVO;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.DiskOfferingVO.Type;
import com.cloud.utils.db.Attribute;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
@Local(value={DiskOfferingJoinDao.class})
public class DiskOfferingJoinDaoImpl extends GenericDaoBase<DiskOfferingJoinVO, Long> implements DiskOfferingJoinDao {
public static final Logger s_logger = Logger.getLogger(DiskOfferingJoinDaoImpl.class);
private SearchBuilder<DiskOfferingJoinVO> dofIdSearch;
private final Attribute _typeAttr;
protected DiskOfferingJoinDaoImpl() {
dofIdSearch = createSearchBuilder();
dofIdSearch.and("id", dofIdSearch.entity().getId(), SearchCriteria.Op.EQ);
dofIdSearch.done();
_typeAttr = _allAttributes.get("type");
this._count = "select count(distinct id) from disk_offering_view WHERE ";
}
@Override
public DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO offering) {
DiskOfferingResponse diskOfferingResponse = new DiskOfferingResponse();
diskOfferingResponse.setId(offering.getUuid());
diskOfferingResponse.setName(offering.getName());
diskOfferingResponse.setDisplayText(offering.getDisplayText());
diskOfferingResponse.setCreated(offering.getCreated());
diskOfferingResponse.setDiskSize(offering.getDiskSize() / (1024 * 1024 * 1024));
diskOfferingResponse.setDomain(offering.getDomainName());
diskOfferingResponse.setDomainId(offering.getDomainUuid());
diskOfferingResponse.setTags(offering.getTags());
diskOfferingResponse.setCustomized(offering.isCustomized());
diskOfferingResponse.setStorageType(offering.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
diskOfferingResponse.setObjectName("diskoffering");
return diskOfferingResponse;
}
@Override
public DiskOfferingJoinVO newDiskOfferingView(DiskOffering offering) {
SearchCriteria<DiskOfferingJoinVO> sc = dofIdSearch.create();
sc.setParameters("id", offering.getId());
List<DiskOfferingJoinVO> offerings = searchIncludingRemoved(sc, null, null, false);
assert offerings != null && offerings.size() == 1 : "No disk offering found for offering id " + offering.getId();
return offerings.get(0);
}
@Override
public List<DiskOfferingJoinVO> searchIncludingRemoved(SearchCriteria<DiskOfferingJoinVO> sc, final Filter filter, final Boolean lock, final boolean cache) {
sc.addAnd(_typeAttr, Op.EQ, Type.Disk);
return super.searchIncludingRemoved(sc, filter, lock, cache);
}
@Override
public <K> List<K> customSearchIncludingRemoved(SearchCriteria<K> sc, final Filter filter) {
sc.addAnd(_typeAttr, Op.EQ, Type.Disk);
return super.customSearchIncludingRemoved(sc, filter);
}
}

View File

@ -77,7 +77,7 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
hostResponse.setCapabilities(host.getCapabilities());
hostResponse.setClusterId(host.getClusterUuid());
hostResponse.setCpuNumber(host.getCpus());
hostResponse.setZoneId(host.getUuid());
hostResponse.setZoneId(host.getZoneUuid());
hostResponse.setDisconnectedOn(host.getDisconnectedOn());
hostResponse.setHypervisor(host.getHypervisorType());
hostResponse.setHostType(host.getType());

View File

@ -0,0 +1,30 @@
// 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.query.dao;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
import com.cloud.offering.ServiceOffering;
import com.cloud.utils.db.GenericDao;
public interface ServiceOfferingJoinDao extends GenericDao<ServiceOfferingJoinVO, Long> {
ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO offering);
ServiceOfferingJoinVO newServiceOfferingView(ServiceOffering offering);
}

View File

@ -0,0 +1,91 @@
// 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.query.dao;
import java.util.List;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import com.cloud.offering.ServiceOffering;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value={ServiceOfferingJoinDao.class})
public class ServiceOfferingJoinDaoImpl extends GenericDaoBase<ServiceOfferingJoinVO, Long> implements ServiceOfferingJoinDao {
public static final Logger s_logger = Logger.getLogger(ServiceOfferingJoinDaoImpl.class);
private SearchBuilder<ServiceOfferingJoinVO> sofIdSearch;
protected ServiceOfferingJoinDaoImpl() {
sofIdSearch = createSearchBuilder();
sofIdSearch.and("id", sofIdSearch.entity().getId(), SearchCriteria.Op.EQ);
sofIdSearch.done();
this._count = "select count(distinct id) from service_offering_view WHERE ";
}
@Override
public ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO offering) {
ServiceOfferingResponse offeringResponse = new ServiceOfferingResponse();
offeringResponse.setId(offering.getUuid());
offeringResponse.setName(offering.getName());
offeringResponse.setIsSystemOffering(offering.isSystemUse());
offeringResponse.setDefaultUse(offering.isDefaultUse());
offeringResponse.setSystemVmType(offering.getSystemVmType());
offeringResponse.setDisplayText(offering.getDisplayText());
offeringResponse.setCpuNumber(offering.getCpu());
offeringResponse.setCpuSpeed(offering.getSpeed());
offeringResponse.setMemory(offering.getRamSize());
offeringResponse.setCreated(offering.getCreated());
offeringResponse.setStorageType(offering.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString()
: ServiceOffering.StorageType.shared.toString());
offeringResponse.setOfferHa(offering.isOfferHA());
offeringResponse.setLimitCpuUse(offering.isLimitCpuUse());
offeringResponse.setTags(offering.getTags());
offeringResponse.setDomain(offering.getDomainName());
offeringResponse.setDomainId(offering.getDomainUuid());
offeringResponse.setNetworkRate(offering.getRateMbps());
offeringResponse.setHostTag(offering.getHostTag());
offeringResponse.setObjectName("serviceoffering");
return offeringResponse;
}
@Override
public ServiceOfferingJoinVO newServiceOfferingView(ServiceOffering offering) {
SearchCriteria<ServiceOfferingJoinVO> sc = sofIdSearch.create();
sc.setParameters("id", offering.getId());
List<ServiceOfferingJoinVO> offerings = searchIncludingRemoved(sc, null, null, false);
assert offerings != null && offerings.size() == 1 : "No service offering found for offering id " + offering.getId();
return offerings.get(0);
}
}

View File

@ -0,0 +1,284 @@
// 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.query.vo;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.org.Grouping.AllocationState;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="data_center_view")
public class DataCenterJoinVO extends BaseViewVO implements InternalIdentity, Identity {
@Id
@Column(name="id")
private long id;
@Column(name="uuid")
private String uuid;
@Column(name="name")
private String name;
@Column(name="description")
private String description = null;
@Column(name="dns1")
private String dns1 = null;
@Column(name="dns2")
private String dns2 = null;
@Column(name="internal_dns1")
private String internalDns1 = null;
@Column(name="internal_dns2")
private String internalDns2 = null;
@Column(name="guest_network_cidr")
private String guestNetworkCidr = null;
@Column(name="domain")
private String domain;
@Column(name="networktype")
@Enumerated(EnumType.STRING)
NetworkType networkType;
@Column(name="dhcp_provider")
private String dhcpProvider;
@Column(name="zone_token")
private String zoneToken;
@Column(name="allocation_state")
@Enumerated(value=EnumType.STRING)
AllocationState allocationState;
@Column(name="is_security_group_enabled")
boolean securityGroupEnabled;
@Column(name="is_local_storage_enabled")
boolean localStorageEnabled;
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
@Column(name="domain_id")
private long domainId;
@Column(name="domain_uuid")
private String domainUuid;
@Column(name="domain_name")
private String domainName;
@Column(name="domain_path")
private String domainPath;
public DataCenterJoinVO() {
}
@Override
public long getId() {
return id;
}
@Override
public void setId(long id) {
this.id = id;
}
@Override
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDns1() {
return dns1;
}
public void setDns1(String dns1) {
this.dns1 = dns1;
}
public String getDns2() {
return dns2;
}
public void setDns2(String dns2) {
this.dns2 = dns2;
}
public String getInternalDns1() {
return internalDns1;
}
public void setInternalDns1(String internalDns1) {
this.internalDns1 = internalDns1;
}
public String getInternalDns2() {
return internalDns2;
}
public void setInternalDns2(String internalDns2) {
this.internalDns2 = internalDns2;
}
public String getGuestNetworkCidr() {
return guestNetworkCidr;
}
public void setGuestNetworkCidr(String guestNetworkCidr) {
this.guestNetworkCidr = guestNetworkCidr;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public NetworkType getNetworkType() {
return networkType;
}
public void setNetworkType(NetworkType networkType) {
this.networkType = networkType;
}
public String getDhcpProvider() {
return dhcpProvider;
}
public void setDhcpProvider(String dhcpProvider) {
this.dhcpProvider = dhcpProvider;
}
public String getZoneToken() {
return zoneToken;
}
public void setZoneToken(String zoneToken) {
this.zoneToken = zoneToken;
}
public AllocationState getAllocationState() {
return allocationState;
}
public void setAllocationState(AllocationState allocationState) {
this.allocationState = allocationState;
}
public boolean isSecurityGroupEnabled() {
return securityGroupEnabled;
}
public void setSecurityGroupEnabled(boolean securityGroupEnabled) {
this.securityGroupEnabled = securityGroupEnabled;
}
public boolean isLocalStorageEnabled() {
return localStorageEnabled;
}
public void setLocalStorageEnabled(boolean localStorageEnabled) {
this.localStorageEnabled = localStorageEnabled;
}
public Date getRemoved() {
return removed;
}
public void setRemoved(Date removed) {
this.removed = removed;
}
public long getDomainId() {
return domainId;
}
public void setDomainId(long domainId) {
this.domainId = domainId;
}
public String getDomainUuid() {
return domainUuid;
}
public void setDomainUuid(String domainUuid) {
this.domainUuid = domainUuid;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getDomainPath() {
return domainPath;
}
public void setDomainPath(String domainPath) {
this.domainPath = domainPath;
}
}

View File

@ -0,0 +1,233 @@
// 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.query.vo;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.storage.DiskOfferingVO.Type;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="disk_offering_view")
public class DiskOfferingJoinVO extends BaseViewVO implements InternalIdentity, Identity {
@Id
@Column(name="id", updatable=false, nullable = false)
private long id;
@Column(name="uuid")
private String uuid;
@Column(name="name")
private String name;
@Column(name="display_text")
private String displayText;
@Column(name="disk_size")
long diskSize;
@Column(name="tags", length=4096)
String tags;
@Column(name="use_local_storage")
private boolean useLocalStorage;
@Column(name="system_use")
private boolean systemUse;
@Column(name="customized")
private boolean customized;
@Column(name="sort_key")
int sortKey;
@Column(name="type")
Type type;
@Column(name=GenericDao.CREATED_COLUMN)
private Date created;
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
@Column(name="domain_id")
private long domainId;
@Column(name="domain_uuid")
private String domainUuid;
@Column(name="domain_name")
private String domainName = null;
@Column(name="domain_path")
private String domainPath = null;
public DiskOfferingJoinVO() {
}
@Override
public long getId() {
return id;
}
@Override
public void setId(long id) {
this.id = id;
}
@Override
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDisplayText() {
return displayText;
}
public void setDisplayText(String displayText) {
this.displayText = displayText;
}
public long getDiskSize() {
return diskSize;
}
public void setDiskSize(long diskSize) {
this.diskSize = diskSize;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public boolean isUseLocalStorage() {
return useLocalStorage;
}
public void setUseLocalStorage(boolean useLocalStorage) {
this.useLocalStorage = useLocalStorage;
}
public boolean isSystemUse() {
return systemUse;
}
public void setSystemUse(boolean systemUse) {
this.systemUse = systemUse;
}
public boolean isCustomized() {
return customized;
}
public void setCustomized(boolean customized) {
this.customized = customized;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getRemoved() {
return removed;
}
public void setRemoved(Date removed) {
this.removed = removed;
}
public long getDomainId() {
return domainId;
}
public void setDomainId(long domainId) {
this.domainId = domainId;
}
public String getDomainUuid() {
return domainUuid;
}
public void setDomainUuid(String domainUuid) {
this.domainUuid = domainUuid;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getDomainPath() {
return domainPath;
}
public void setDomainPath(String domainPath) {
this.domainPath = domainPath;
}
public int getSortKey() {
return sortKey;
}
public void setSortKey(int sortKey) {
this.sortKey = sortKey;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
}

View File

@ -0,0 +1,311 @@
// 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.query.vo;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="service_offering_view")
public class ServiceOfferingJoinVO extends BaseViewVO implements InternalIdentity, Identity {
@Id
@Column(name="id", updatable=false, nullable = false)
private long id;
@Column(name="uuid")
private String uuid;
@Column(name="name")
private String name;
@Column(name="display_text")
private String displayText;
@Column(name="tags", length=4096)
String tags;
@Column(name="use_local_storage")
private boolean useLocalStorage;
@Column(name="system_use")
private boolean systemUse;
@Column(name="cpu")
private int cpu;
@Column(name="speed")
private int speed;
@Column(name="ram_size")
private int ramSize;
@Column(name="nw_rate")
private Integer rateMbps;
@Column(name="mc_rate")
private Integer multicastRateMbps;
@Column(name="ha_enabled")
private boolean offerHA;
@Column(name="limit_cpu_use")
private boolean limitCpuUse;
@Column(name="host_tag")
private String hostTag;
@Column(name="default_use")
private boolean default_use;
@Column(name="vm_type")
private String vm_type;
@Column(name="sort_key")
int sortKey;
@Column(name=GenericDao.CREATED_COLUMN)
private Date created;
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
@Column(name="domain_id")
private long domainId;
@Column(name="domain_uuid")
private String domainUuid;
@Column(name="domain_name")
private String domainName = null;
@Column(name="domain_path")
private String domainPath = null;
public ServiceOfferingJoinVO() {
}
@Override
public long getId() {
return id;
}
@Override
public void setId(long id) {
this.id = id;
}
@Override
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDisplayText() {
return displayText;
}
public void setDisplayText(String displayText) {
this.displayText = displayText;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public boolean isUseLocalStorage() {
return useLocalStorage;
}
public void setUseLocalStorage(boolean useLocalStorage) {
this.useLocalStorage = useLocalStorage;
}
public boolean isSystemUse() {
return systemUse;
}
public void setSystemUse(boolean systemUse) {
this.systemUse = systemUse;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getRemoved() {
return removed;
}
public void setRemoved(Date removed) {
this.removed = removed;
}
public long getDomainId() {
return domainId;
}
public void setDomainId(long domainId) {
this.domainId = domainId;
}
public String getDomainUuid() {
return domainUuid;
}
public void setDomainUuid(String domainUuid) {
this.domainUuid = domainUuid;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getDomainPath() {
return domainPath;
}
public void setDomainPath(String domainPath) {
this.domainPath = domainPath;
}
public int getSortKey() {
return sortKey;
}
public void setSortKey(int sortKey) {
this.sortKey = sortKey;
}
public int getCpu() {
return cpu;
}
public void setCpu(int cpu) {
this.cpu = cpu;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int getRamSize() {
return ramSize;
}
public void setRamSize(int ramSize) {
this.ramSize = ramSize;
}
public Integer getRateMbps() {
return rateMbps;
}
public void setRateMbps(Integer rateMbps) {
this.rateMbps = rateMbps;
}
public Integer getMulticastRateMbps() {
return multicastRateMbps;
}
public void setMulticastRateMbps(Integer multicastRateMbps) {
this.multicastRateMbps = multicastRateMbps;
}
public boolean isOfferHA() {
return offerHA;
}
public void setOfferHA(boolean offerHA) {
this.offerHA = offerHA;
}
public boolean isLimitCpuUse() {
return limitCpuUse;
}
public void setLimitCpuUse(boolean limitCpuUse) {
this.limitCpuUse = limitCpuUse;
}
public String getHostTag() {
return hostTag;
}
public void setHostTag(String hostTag) {
this.hostTag = hostTag;
}
public boolean isDefaultUse() {
return default_use;
}
public void setDefaultUse(boolean default_use) {
this.default_use = default_use;
}
public String getSystemVmType() {
return vm_type;
}
public void setSystemVmType(String vm_type) {
this.vm_type = vm_type;
}
}

View File

@ -27,6 +27,9 @@ import com.cloud.alert.dao.AlertDaoImpl;
import com.cloud.api.query.QueryManagerImpl;
import com.cloud.api.query.dao.AccountJoinDaoImpl;
import com.cloud.api.query.dao.AsyncJobJoinDaoImpl;
import com.cloud.api.query.dao.DataCenterJoinDaoImpl;
import com.cloud.api.query.dao.DiskOfferingJoinDaoImpl;
import com.cloud.api.query.dao.ServiceOfferingJoinDaoImpl;
import com.cloud.api.query.dao.DomainRouterJoinDaoImpl;
import com.cloud.api.query.dao.InstanceGroupJoinDaoImpl;
import com.cloud.api.query.dao.ProjectAccountJoinDaoImpl;
@ -392,6 +395,9 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
addDao("AccountJoinDao", AccountJoinDaoImpl.class);
addDao("AsyncJobJoinDao", AsyncJobJoinDaoImpl.class);
addDao("StoragePoolJoinDao", StoragePoolJoinDaoImpl.class);
addDao("DiskOfferingJoinDao", DiskOfferingJoinDaoImpl.class);
addDao("ServiceOfferingJoinDao", ServiceOfferingJoinDaoImpl.class);
addDao("DataCenterJoinDao", DataCenterJoinDaoImpl.class);
}
@Override

View File

@ -51,6 +51,13 @@ public class EntityManagerImpl implements EntityManager, Manager {
return dao.findByUuid(uuid);
}
@Override
public <T> T findByUuidIncludingRemoved(Class<T> entityType, String uuid) {
// Finds and returns a unique VO using uuid, null if entity not found in db
GenericDao<? extends T, String> dao = (GenericDao<? extends T, String>)GenericDaoBase.getDao(entityType);
return dao.findByUuidIncludingRemoved(uuid);
}
@Override
public <T> T findByXId(Class<T> entityType, String xid) {
return null;

View File

@ -1814,9 +1814,6 @@ public class NetworkServiceImpl implements NetworkService, Manager {
throw new InvalidParameterValueException("Please specify valid integers for the vlan range.");
}
//check for vnet conflicts with other physical network(s) in the zone
checkGuestVnetsConflicts(zoneId, vnetStart, vnetEnd, null);
if ((vnetStart > vnetEnd) || (vnetStart < 0) || (vnetEnd > 4096)) {
s_logger.warn("Invalid vnet range: start range:" + vnetStart + " end range:" + vnetEnd);
throw new InvalidParameterValueException("Vnet range should be between 0-4096 and start range should be lesser than or equal to end range");
@ -1995,9 +1992,6 @@ public class NetworkServiceImpl implements NetworkService, Manager {
throw new InvalidParameterValueException("Vnet range has to be" + rangeMessage + " and start range should be lesser than or equal to stop range");
}
//check if new vnet conflicts with vnet ranges of other physical networks
checkGuestVnetsConflicts(network.getDataCenterId(), newStartVnet, newEndVnet, network.getId());
if (physicalNetworkHasAllocatedVnets(network.getDataCenterId(), network.getId())) {
String[] existingRange = network.getVnet().split("-");
int existingStartVnet = Integer.parseInt(existingRange[0]);
@ -2042,24 +2036,6 @@ public class NetworkServiceImpl implements NetworkService, Manager {
return network;
}
protected void checkGuestVnetsConflicts(long zoneId, int newStartVnet, int newEndVnet, Long pNtwkIdToSkip) {
List<? extends PhysicalNetwork> pNtwks = _physicalNetworkDao.listByZone(zoneId);
for (PhysicalNetwork pNtwk : pNtwks) {
// skip my own network and networks that don't have vnet range set
if ((pNtwk.getVnet() == null || pNtwk.getVnet().isEmpty()) || (pNtwkIdToSkip != null && pNtwkIdToSkip == pNtwk.getId())) {
continue;
}
String[] existingRange = pNtwk.getVnet().split("-");
int startVnet = Integer.parseInt(existingRange[0]);
int endVnet = Integer.parseInt(existingRange[1]);
if ((newStartVnet >= startVnet && newStartVnet <= endVnet)
|| (newEndVnet <= endVnet && newEndVnet >= startVnet)) {
throw new InvalidParameterValueException("Vnet range for physical network conflicts with another " +
"physical network's vnet in the zone");
}
}
}
private boolean physicalNetworkHasAllocatedVnets(long zoneId, long physicalNetworkId) {
return !_dcDao.listAllocatedVnets(physicalNetworkId).isEmpty();
}

View File

@ -560,8 +560,9 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
}
@Override
public List<SwiftVO> listSwifts(ListSwiftsCmd cmd) {
return _swiftMgr.listSwifts(cmd);
public Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd) {
Pair<List<SwiftVO>, Integer> swifts = _swiftMgr.listSwifts(cmd);
return new Pair<List<? extends Swift>, Integer>(swifts.first(), swifts.second());
}
@Override

View File

@ -553,8 +553,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
return;
}
String already = _configDao.getValue("ssh.privatekey");
String homeDir = null;
homeDir = Script.runSimpleBashScript("echo ~" + username);
String homeDir = System.getProperty("user.home");
if (homeDir == null) {
throw new CloudRuntimeException("Cannot get home directory for account: " + username);
}

View File

@ -46,7 +46,6 @@ import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
import org.apache.cloudstack.api.command.admin.resource.ListAlertsCmd;
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
import org.apache.cloudstack.api.command.admin.systemvm.DestroySystemVmCmd;
import org.apache.cloudstack.api.command.admin.systemvm.UpgradeSystemVMCmd;
import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
@ -55,8 +54,6 @@ import org.apache.cloudstack.api.command.user.guest.ListGuestOsCategoriesCmd;
import org.apache.cloudstack.api.command.user.guest.ListGuestOsCmd;
import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd;
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
import org.apache.cloudstack.api.command.user.ssh.ListSSHKeyPairsCmd;
import org.apache.cloudstack.api.command.user.ssh.DeleteSSHKeyPairCmd;
import org.apache.cloudstack.api.command.user.ssh.RegisterSSHKeyPairCmd;
@ -91,9 +88,6 @@ import org.apache.cloudstack.api.command.admin.systemvm.StopSystemVmCmd;
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
import com.cloud.api.query.dao.DomainRouterJoinDao;
import com.cloud.api.query.dao.InstanceGroupJoinDao;
import org.apache.cloudstack.api.command.user.vmgroup.UpdateVMGroupCmd;
import org.apache.cloudstack.api.command.admin.resource.UploadCustomCertificateCmd;
import org.apache.cloudstack.api.response.ExtractResponse;
@ -103,13 +97,11 @@ import com.cloud.async.AsyncJobManager;
import com.cloud.async.AsyncJobResult;
import com.cloud.async.AsyncJobVO;
import com.cloud.async.BaseAsyncJobExecutor;
import com.cloud.async.dao.AsyncJobDao;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.Configuration;
import com.cloud.configuration.ConfigurationVO;
import com.cloud.configuration.dao.ConfigurationDao;
@ -139,8 +131,6 @@ import com.cloud.event.EventTypes;
import com.cloud.event.EventUtils;
import com.cloud.event.EventVO;
import com.cloud.event.dao.EventDao;
import com.cloud.event.dao.EventJoinDao;
import com.cloud.exception.CloudAuthenticationException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.OperationTimedoutException;
@ -179,7 +169,6 @@ import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.server.auth.UserAuthenticator;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.GuestOS;
import com.cloud.storage.GuestOSCategoryVO;
import com.cloud.storage.GuestOSVO;
@ -187,7 +176,6 @@ import com.cloud.storage.GuestOsCategory;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePool;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.Upload;
import com.cloud.storage.Upload.Mode;
@ -195,7 +183,6 @@ import com.cloud.storage.UploadVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.GuestOSCategoryDao;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.StoragePoolDao;
@ -220,12 +207,10 @@ import com.cloud.user.UserVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.SSHKeyPairDao;
import com.cloud.user.dao.UserDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.EnumUtils;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
@ -258,7 +243,6 @@ import com.cloud.vm.VirtualMachineProfileImpl;
import com.cloud.vm.dao.ConsoleProxyDao;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.InstanceGroupDao;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.SecondaryStorageVmDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
@ -274,12 +258,10 @@ public class ManagementServerImpl implements ManagementServer {
private final AlertManager _alertMgr;
private final IPAddressDao _publicIpAddressDao;
private final DomainRouterDao _routerDao;
private final DomainRouterJoinDao _routerJoinDao;
private final ConsoleProxyDao _consoleProxyDao;
private final ClusterDao _clusterDao;
private final SecondaryStorageVmDao _secStorageVmDao;
private final EventDao _eventDao;
private final EventJoinDao _eventJoinDao;
private final DataCenterDao _dcDao;
private final VlanDao _vlanDao;
private final AccountVlanMapDao _accountVlanMapDao;
@ -294,7 +276,6 @@ public class ManagementServerImpl implements ManagementServer {
private final SwiftManager _swiftMgr;
private final S3Manager _s3Mgr;
private final ServiceOfferingDao _offeringsDao;
private final DiskOfferingDao _diskOfferingDao;
private final VMTemplateDao _templateDao;
private final DomainDao _domainDao;
private final AccountDao _accountDao;
@ -303,25 +284,21 @@ public class ManagementServerImpl implements ManagementServer {
private final GuestOSDao _guestOSDao;
private final GuestOSCategoryDao _guestOSCategoryDao;
private final StoragePoolDao _poolDao;
private final NicDao _nicDao;
private final NetworkDao _networkDao;
private final StorageManager _storageMgr;
private final VirtualMachineManager _itMgr;
private final HostPodDao _hostPodDao;
private final VMInstanceDao _vmInstanceDao;
private final VolumeDao _volumeDao;
private final AsyncJobDao _jobDao;
private final AsyncJobManager _asyncMgr;
private final int _purgeDelay;
private final InstanceGroupDao _vmGroupDao;
private final InstanceGroupJoinDao _vmGroupJoinDao;
private final UploadMonitor _uploadMonitor;
private final UploadDao _uploadDao;
private final SSHKeyPairDao _sshKeyPairDao;
private final LoadBalancerDao _loadbalancerDao;
private final HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
private final Adapters<HostAllocator> _hostAllocators;
private final ConfigurationManager _configMgr;
private final ResourceTagDao _resourceTagDao;
@Inject
@ -340,6 +317,8 @@ public class ManagementServerImpl implements ManagementServer {
private final Map<String, String> _configs;
// even though this _statsCollector is never used here, but we create the singleton here to avoid null pointer exception in other places
// like ApiDbUtils to reference StatsCollector instance.
private final StatsCollector _statsCollector;
private final Map<String, Boolean> _availableIdsMap;
@ -352,9 +331,7 @@ public class ManagementServerImpl implements ManagementServer {
ComponentLocator locator = ComponentLocator.getLocator(Name);
_configDao = locator.getDao(ConfigurationDao.class);
_routerDao = locator.getDao(DomainRouterDao.class);
_routerJoinDao = locator.getDao(DomainRouterJoinDao.class);
_eventDao = locator.getDao(EventDao.class);
_eventJoinDao = locator.getDao(EventJoinDao.class);
_dcDao = locator.getDao(DataCenterDao.class);
_vlanDao = locator.getDao(VlanDao.class);
_accountVlanMapDao = locator.getDao(AccountVlanMapDao.class);
@ -362,9 +339,7 @@ public class ManagementServerImpl implements ManagementServer {
_hostDao = locator.getDao(HostDao.class);
_detailsDao = locator.getDao(HostDetailsDao.class);
_hostPodDao = locator.getDao(HostPodDao.class);
_jobDao = locator.getDao(AsyncJobDao.class);
_clusterDao = locator.getDao(ClusterDao.class);
_nicDao = locator.getDao(NicDao.class);
_networkDao = locator.getDao(NetworkDao.class);
_loadbalancerDao = locator.getDao(LoadBalancerDao.class);
@ -382,7 +357,6 @@ public class ManagementServerImpl implements ManagementServer {
_userDao = locator.getDao(UserDao.class);
_userVmDao = locator.getDao(UserVmDao.class);
_offeringsDao = locator.getDao(ServiceOfferingDao.class);
_diskOfferingDao = locator.getDao(DiskOfferingDao.class);
_templateDao = locator.getDao(VMTemplateDao.class);
_domainDao = locator.getDao(DomainDao.class);
_accountDao = locator.getDao(AccountDao.class);
@ -392,7 +366,6 @@ public class ManagementServerImpl implements ManagementServer {
_guestOSCategoryDao = locator.getDao(GuestOSCategoryDao.class);
_poolDao = locator.getDao(StoragePoolDao.class);
_vmGroupDao = locator.getDao(InstanceGroupDao.class);
_vmGroupJoinDao = locator.getDao(InstanceGroupJoinDao.class);
_uploadDao = locator.getDao(UploadDao.class);
_configs = _configDao.getConfiguration();
_vmInstanceDao = locator.getDao(VMInstanceDao.class);
@ -403,7 +376,6 @@ public class ManagementServerImpl implements ManagementServer {
_itMgr = locator.getManager(VirtualMachineManager.class);
_ksMgr = locator.getManager(KeystoreManager.class);
_resourceMgr = locator.getManager(ResourceManager.class);
_configMgr = locator.getManager(ConfigurationManager.class);
_resourceTagDao = locator.getDao(ResourceTagDao.class);
_hypervisorCapabilitiesDao = locator.getDao(HypervisorCapabilitiesDao.class);
@ -444,119 +416,7 @@ public class ManagementServerImpl implements ManagementServer {
return PasswordGenerator.generateRandomPassword(6);
}
@Override
public List<DataCenterVO> listDataCenters(ListZonesByCmd cmd) {
Account account = UserContext.current().getCaller();
List<DataCenterVO> dcs = null;
Long domainId = cmd.getDomainId();
Long id = cmd.getId();
boolean removeDisabledZones = false;
String keyword = cmd.getKeyword();
if (domainId != null) {
// for domainId != null
// right now, we made the decision to only list zones associated
// with this domain
dcs = _dcDao.findZonesByDomainId(domainId, keyword); // private
// zones
} else if ((account == null || account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
if (keyword != null) {
dcs = _dcDao.findByKeyword(keyword);
} else {
dcs = _dcDao.listAll(); // all zones
}
} else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) {
// it was decided to return all zones for the user's domain, and
// everything above till root
// list all zones belonging to this domain, and all of its parents
// check the parent, if not null, add zones for that parent to list
dcs = new ArrayList<DataCenterVO>();
DomainVO domainRecord = _domainDao.findById(account.getDomainId());
if (domainRecord != null) {
while (true) {
dcs.addAll(_dcDao.findZonesByDomainId(domainRecord.getId(), keyword));
if (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
} else {
break;
}
}
}
// add all public zones too
dcs.addAll(_dcDao.listPublicZones(keyword));
removeDisabledZones = true;
} else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
// it was decided to return all zones for the domain admin, and
// everything above till root
dcs = new ArrayList<DataCenterVO>();
DomainVO domainRecord = _domainDao.findById(account.getDomainId());
// this covers path till root
if (domainRecord != null) {
DomainVO localRecord = domainRecord;
while (true) {
dcs.addAll(_dcDao.findZonesByDomainId(localRecord.getId(), keyword));
if (localRecord.getParent() != null) {
localRecord = _domainDao.findById(localRecord.getParent());
} else {
break;
}
}
}
// this covers till leaf
if (domainRecord != null) {
// find all children for this domain based on a like search by
// path
List<DomainVO> allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId());
List<Long> allChildDomainIds = new ArrayList<Long>();
// create list of domainIds for search
for (DomainVO domain : allChildDomains) {
allChildDomainIds.add(domain.getId());
}
// now make a search for zones based on this
if (allChildDomainIds.size() > 0) {
List<DataCenterVO> childZones = _dcDao.findChildZones((allChildDomainIds.toArray()), keyword);
dcs.addAll(childZones);
}
}
// add all public zones too
dcs.addAll(_dcDao.listPublicZones(keyword));
removeDisabledZones = true;
}
if (removeDisabledZones) {
dcs.removeAll(_dcDao.listDisabledZones());
}
Boolean available = cmd.isAvailable();
if (account != null) {
if ((available != null) && Boolean.FALSE.equals(available)) {
List<DomainRouterVO> routers = _routerDao.listBy(account.getId());
for (Iterator<DataCenterVO> iter = dcs.iterator(); iter.hasNext();) {
DataCenterVO dc = iter.next();
boolean found = false;
for (DomainRouterVO router : routers) {
if (dc.getId() == router.getDataCenterIdToDeployIn()) {
found = true;
break;
}
}
if (!found) {
iter.remove();
}
}
}
}
if (id != null) {
List<DataCenterVO> singleZone = new ArrayList<DataCenterVO>();
for (DataCenterVO zone : dcs) {
if (zone.getId() == id) {
singleZone.add(zone);
}
}
return singleZone;
}
return dcs;
}
@Override
public HostVO getHostBy(long hostId) {
@ -633,221 +493,6 @@ public class ManagementServerImpl implements ManagementServer {
return cal.getTime();
}
// This method is used for permissions check for both disk and service
// offerings
private boolean isPermissible(Long accountDomainId, Long offeringDomainId) {
if (accountDomainId == offeringDomainId) {
return true; // account and service offering in same domain
}
DomainVO domainRecord = _domainDao.findById(accountDomainId);
if (domainRecord != null) {
while (true) {
if (domainRecord.getId() == offeringDomainId) {
return true;
}
// try and move on to the next domain
if (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
} else {
break;
}
}
}
return false;
}
@Override
public List<ServiceOfferingVO> searchForServiceOfferings(ListServiceOfferingsCmd cmd) {
// Note
// The list method for offerings is being modified in accordance with
// discussion with Will/Kevin
// For now, we will be listing the following based on the usertype
// 1. For root, we will list all offerings
// 2. For domainAdmin and regular users, we will list everything in
// their domains+parent domains ... all the way
// till
// root
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = (isAscending == null ? true : isAscending);
Filter searchFilter = new Filter(ServiceOfferingVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchCriteria<ServiceOfferingVO> sc = _offeringsDao.createSearchCriteria();
Account caller = UserContext.current().getCaller();
Object name = cmd.getServiceOfferingName();
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long vmId = cmd.getVirtualMachineId();
Long domainId = cmd.getDomainId();
Boolean isSystem = cmd.getIsSystem();
String vmTypeStr = cmd.getSystemVmType();
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && isSystem) {
throw new InvalidParameterValueException("Only ROOT admins can access system's offering");
}
// Keeping this logic consistent with domain specific zones
// if a domainId is provided, we just return the so associated with this
// domain
if (domainId != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
// check if the user's domain == so's domain || user's domain is a
// child of so's domain
if (!isPermissible(caller.getDomainId(), domainId)) {
throw new PermissionDeniedException("The account:" + caller.getAccountName()
+ " does not fall in the same domain hierarchy as the service offering");
}
}
// For non-root users
if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
|| caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
if (isSystem) {
throw new InvalidParameterValueException("Only root admins can access system's offering");
}
return searchServiceOfferingsInternal(caller, name, id, vmId, keyword, searchFilter);
}
// for root users, the existing flow
if (caller.getDomainId() != 1 && isSystem) { // NON ROOT admin
throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering");
}
if (keyword != null) {
SearchCriteria<ServiceOfferingVO> ssc = _offeringsDao.createSearchCriteria();
ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
} else if (vmId != null) {
UserVmVO vmInstance = _userVmDao.findById(vmId);
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id");
ex.addProxyObject(vmInstance, vmId, "vmId");
throw ex;
}
_accountMgr.checkAccess(caller, null, true, vmInstance);
ServiceOfferingVO offering = _offeringsDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId());
// Only return offerings with the same Guest IP type and storage
// pool preference
// sc.addAnd("guestIpType", SearchCriteria.Op.EQ,
// offering.getGuestIpType());
sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage());
}
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
}
if (isSystem != null) {
sc.addAnd("systemUse", SearchCriteria.Op.EQ, isSystem);
}
if (name != null) {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
}
if (domainId != null) {
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
}
if (vmTypeStr != null) {
sc.addAnd("vm_type", SearchCriteria.Op.EQ, vmTypeStr);
}
sc.addAnd("removed", SearchCriteria.Op.NULL);
return _offeringsDao.search(sc, searchFilter);
}
private List<ServiceOfferingVO> searchServiceOfferingsInternal(Account caller, Object name, Object id, Long vmId, Object keyword,
Filter searchFilter) {
// it was decided to return all offerings for the user's domain, and
// everything above till root (for normal user
// or
// domain admin)
// list all offerings belonging to this domain, and all of its parents
// check the parent, if not null, add offerings for that parent to list
List<ServiceOfferingVO> sol = new ArrayList<ServiceOfferingVO>();
DomainVO domainRecord = _domainDao.findById(caller.getDomainId());
boolean includePublicOfferings = true;
if (domainRecord != null) {
while (true) {
if (id != null) {
ServiceOfferingVO so = _offeringsDao.findById((Long) id);
if (so != null) {
sol.add(so);
}
return sol;
}
SearchCriteria<ServiceOfferingVO> sc = _offeringsDao.createSearchCriteria();
if (keyword != null) {
includePublicOfferings = false;
SearchCriteria<ServiceOfferingVO> ssc = _offeringsDao.createSearchCriteria();
ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
} else if (vmId != null) {
UserVmVO vmInstance = _userVmDao.findById(vmId);
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
ex.addProxyObject(vmInstance, vmId, "vmId");
throw ex;
}
_accountMgr.checkAccess(caller, null, false, vmInstance);
ServiceOfferingVO offering = _offeringsDao.findById(vmInstance.getServiceOfferingId());
sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId());
sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage());
}
if (name != null) {
includePublicOfferings = false;
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
}
sc.addAnd("systemUse", SearchCriteria.Op.EQ, false);
// for this domain
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId());
// don't return removed service offerings
sc.addAnd("removed", SearchCriteria.Op.NULL);
// search and add for this domain
sol.addAll(_offeringsDao.search(sc, searchFilter));
// try and move on to the next domain
if (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
} else {
break;// now we got all the offerings for this user/dom adm
}
}
} else {
s_logger.error("Could not find the domainId for account:" + caller.getAccountName());
throw new CloudAuthenticationException("Could not find the domainId for account:" + caller.getAccountName());
}
// add all the public offerings to the sol list before returning
if (includePublicOfferings) {
sol.addAll(_offeringsDao.findPublicServiceOfferings());
}
return sol;
}
@Override
public List<? extends Cluster> searchForClusters(long zoneId, Long startIndex, Long pageSizeVal, String hypervisorType) {
@ -997,7 +642,7 @@ public class ManagementServerImpl implements ManagementServer {
Pair<List<HostVO>, Integer> allHostsInClusterPair = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, null, null, null);
// filter out the current host
// filter out the current host
List<HostVO> allHostsInCluster = allHostsInClusterPair.first();
allHostsInCluster.remove(srcHost);
Pair<List<? extends Host>, Integer> otherHostsInCluster = new Pair<List <? extends Host>, Integer>(allHostsInCluster, new Integer(allHostsInClusterPair.second().intValue()-1));
@ -2153,169 +1798,7 @@ public class ManagementServerImpl implements ManagementServer {
|| (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
}
private List<DiskOfferingVO> searchDiskOfferingsInternal(Account account, Object name, Object id, Object keyword, Filter searchFilter) {
// it was decided to return all offerings for the user's domain, and
// everything above till root (for normal user
// or
// domain admin)
// list all offerings belonging to this domain, and all of its parents
// check the parent, if not null, add offerings for that parent to list
List<DiskOfferingVO> dol = new ArrayList<DiskOfferingVO>();
DomainVO domainRecord = _domainDao.findById(account.getDomainId());
boolean includePublicOfferings = true;
if (domainRecord != null) {
while (true) {
SearchBuilder<DiskOfferingVO> sb = _diskOfferingDao.createSearchBuilder();
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NULL);
SearchCriteria<DiskOfferingVO> sc = sb.create();
if (keyword != null) {
includePublicOfferings = false;
SearchCriteria<DiskOfferingVO> ssc = _diskOfferingDao.createSearchCriteria();
ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (name != null) {
includePublicOfferings = false;
sc.setParameters("name", "%" + name + "%");
}
if (id != null) {
includePublicOfferings = false;
sc.setParameters("id", id);
}
// for this domain
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId());
// search and add for this domain
dol.addAll(_diskOfferingDao.search(sc, searchFilter));
// try and move on to the next domain
if (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
} else {
break;// now we got all the offerings for this user/dom adm
}
}
} else {
s_logger.error("Could not find the domainId for account:" + account.getAccountName());
throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName());
}
// add all the public offerings to the sol list before returning
if (includePublicOfferings) {
dol.addAll(_diskOfferingDao.findPublicDiskOfferings());
}
return dol;
}
@Override
public List<DiskOfferingVO> searchForDiskOfferings(ListDiskOfferingsCmd cmd) {
// Note
// The list method for offerings is being modified in accordance with
// discussion with Will/Kevin
// For now, we will be listing the following based on the usertype
// 1. For root, we will list all offerings
// 2. For domainAdmin and regular users, we will list everything in
// their domains+parent domains ... all the way
// till
// root
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = (isAscending == null ? true : isAscending);
Filter searchFilter = new Filter(DiskOfferingVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<DiskOfferingVO> sb = _diskOfferingDao.createSearchBuilder();
// SearchBuilder and SearchCriteria are now flexible so that the search
// builder can be built with all possible
// search terms and only those with criteria can be set. The proper SQL
// should be generated as a result.
Account account = UserContext.current().getCaller();
Object name = cmd.getDiskOfferingName();
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long domainId = cmd.getDomainId();
// Keeping this logic consistent with domain specific zones
// if a domainId is provided, we just return the disk offering
// associated with this domain
if (domainId != null) {
if (account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
return _diskOfferingDao.listByDomainId(domainId);// no perm
// check
} else {
// check if the user's domain == do's domain || user's domain is
// a child of so's domain
if (isPermissible(account.getDomainId(), domainId)) {
// perm check succeeded
return _diskOfferingDao.listByDomainId(domainId);
} else {
throw new PermissionDeniedException("The account:" + account.getAccountName()
+ " does not fall in the same domain hierarchy as the disk offering");
}
}
}
// For non-root users
if ((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
|| account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
return searchDiskOfferingsInternal(account, name, id, keyword, searchFilter);
}
// For root users, preserving existing flow
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NULL);
// FIXME: disk offerings should search back up the hierarchy for
// available disk offerings...
/*
* sb.addAnd("domainId", sb.entity().getDomainId(),
* SearchCriteria.Op.EQ); if (domainId != null) {
* SearchBuilder<DomainVO> domainSearch =
* _domainDao.createSearchBuilder(); domainSearch.addAnd("path",
* domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
* sb.join("domainSearch", domainSearch, sb.entity().getDomainId(),
* domainSearch.entity().getId()); }
*/
SearchCriteria<DiskOfferingVO> sc = sb.create();
if (keyword != null) {
SearchCriteria<DiskOfferingVO> ssc = _diskOfferingDao.createSearchCriteria();
ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (name != null) {
sc.setParameters("name", "%" + name + "%");
}
if (id != null) {
sc.setParameters("id", id);
}
// FIXME: disk offerings should search back up the hierarchy for
// available disk offerings...
/*
* if (domainId != null) { sc.setParameters("domainId", domainId); //
* //DomainVO domain = _domainDao.findById((Long)domainId); // // I want
* to join on user_vm.domain_id = domain.id where domain.path like
* 'foo%' //sc.setJoinParameters("domainSearch", "path",
* domain.getPath() + "%"); // }
*/
return _diskOfferingDao.search(sc, searchFilter);
}
@Override
public List<Class<?>> getCommands() {
@ -3321,6 +2804,7 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public void enableAdminUser(String password) {
String encodedPassword = null;

View File

@ -20,6 +20,7 @@ import java.util.List;
import com.cloud.storage.SnapshotPolicyVO;
import com.cloud.utils.DateUtil.IntervalType;
import com.cloud.utils.Pair;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDao;
@ -29,6 +30,8 @@ import com.cloud.utils.db.GenericDao;
public interface SnapshotPolicyDao extends GenericDao<SnapshotPolicyVO, Long> {
List<SnapshotPolicyVO> listByVolumeId(long volumeId);
List<SnapshotPolicyVO> listByVolumeId(long volumeId, Filter filter);
Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId);
Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId, Filter filter);
SnapshotPolicyVO findOneByVolumeInterval(long volumeId, IntervalType intvType);
List<SnapshotPolicyVO> listActivePolicies();
SnapshotPolicyVO findOneByVolume(long volumeId);

View File

@ -23,6 +23,7 @@ import javax.ejb.Local;
import com.cloud.storage.SnapshotPolicyVO;
import com.cloud.utils.DateUtil.IntervalType;
import com.cloud.utils.Pair;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
@ -33,7 +34,7 @@ public class SnapshotPolicyDaoImpl extends GenericDaoBase<SnapshotPolicyVO, Long
private final SearchBuilder<SnapshotPolicyVO> VolumeIdSearch;
private final SearchBuilder<SnapshotPolicyVO> VolumeIdIntervalSearch;
private final SearchBuilder<SnapshotPolicyVO> ActivePolicySearch;
@Override
public SnapshotPolicyVO findOneByVolumeInterval(long volumeId, IntervalType intvType) {
SearchCriteria<SnapshotPolicyVO> sc = VolumeIdIntervalSearch.create();
@ -41,7 +42,7 @@ public class SnapshotPolicyDaoImpl extends GenericDaoBase<SnapshotPolicyVO, Long
sc.setParameters("interval", intvType.ordinal());
return findOneBy(sc);
}
@Override
public SnapshotPolicyVO findOneByVolume(long volumeId) {
SearchCriteria<SnapshotPolicyVO> sc = VolumeIdSearch.create();
@ -49,12 +50,12 @@ public class SnapshotPolicyDaoImpl extends GenericDaoBase<SnapshotPolicyVO, Long
sc.setParameters("active", true);
return findOneBy(sc);
}
@Override
public List<SnapshotPolicyVO> listByVolumeId(long volumeId) {
return listByVolumeId(volumeId, null);
}
@Override
public List<SnapshotPolicyVO> listByVolumeId(long volumeId, Filter filter) {
SearchCriteria<SnapshotPolicyVO> sc = VolumeIdSearch.create();
@ -62,18 +63,31 @@ public class SnapshotPolicyDaoImpl extends GenericDaoBase<SnapshotPolicyVO, Long
sc.setParameters("active", true);
return listBy(sc, filter);
}
@Override
public Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId) {
return listAndCountByVolumeId(volumeId, null);
}
@Override
public Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId, Filter filter) {
SearchCriteria<SnapshotPolicyVO> sc = VolumeIdSearch.create();
sc.setParameters("volumeId", volumeId);
sc.setParameters("active", true);
return searchAndCount(sc, filter);
}
protected SnapshotPolicyDaoImpl() {
VolumeIdSearch = createSearchBuilder();
VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
VolumeIdSearch.and("active", VolumeIdSearch.entity().isActive(), SearchCriteria.Op.EQ);
VolumeIdSearch.done();
VolumeIdIntervalSearch = createSearchBuilder();
VolumeIdIntervalSearch.and("volumeId", VolumeIdIntervalSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
VolumeIdIntervalSearch.and("interval", VolumeIdIntervalSearch.entity().getInterval(), SearchCriteria.Op.EQ);
VolumeIdIntervalSearch.done();
ActivePolicySearch = createSearchBuilder();
ActivePolicySearch.and("active", ActivePolicySearch.entity().isActive(), SearchCriteria.Op.EQ);
ActivePolicySearch.done();
@ -84,5 +98,5 @@ public class SnapshotPolicyDaoImpl extends GenericDaoBase<SnapshotPolicyVO, Long
SearchCriteria<SnapshotPolicyVO> sc = ActivePolicySearch.create();
sc.setParameters("active", true);
return listIncludingRemovedBy(sc);
}
}
}

View File

@ -69,6 +69,7 @@ import com.cloud.exception.StorageUnavailableException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.PhysicalNetworkTrafficType;
import com.cloud.org.Grouping;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.resource.ResourceManager;
@ -177,7 +178,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
private SwiftManager _swiftMgr;
@Inject
private S3Manager _s3Mgr;
@Inject
@Inject
private SecondaryStorageVmManager _ssvmMgr;
@Inject
private ResourceManager _resourceMgr;
@ -187,7 +188,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
private VolumeDao _volumeDao;
@Inject
private ResourceTagDao _resourceTagDao;
String _name;
private int _totalRetries;
private int _pauseInterval;
@ -197,15 +198,15 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
protected SearchBuilder<SnapshotVO> PolicySnapshotSearch;
protected SearchBuilder<SnapshotPolicyVO> PoliciesForSnapSearch;
protected Answer sendToPool(Volume vol, Command cmd) {
StoragePool pool = _storagePoolDao.findById(vol.getPoolId());
long[] hostIdsToTryFirst = null;
Long vmHostId = getHostIdForSnapshotOperation(vol);
if (vmHostId != null) {
hostIdsToTryFirst = new long[] { vmHostId };
}
@ -280,7 +281,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
ManageSnapshotCommand cmd = new ManageSnapshotCommand(snapshotId, volume.getPath(), srcPool, preSnapshotPath, snapshot.getName(), vmName);
ManageSnapshotAnswer answer = (ManageSnapshotAnswer) sendToPool(volume, cmd);
// Update the snapshot in the database
if ((answer != null) && answer.getResult()) {
@ -298,7 +299,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
_snapshotDao.update(snapshotId, snapshot);
} else {
long preSnapshotId = 0;
if (preSnapshotVO != null && preSnapshotVO.getBackupSnapshotId() != null) {
preSnapshotId = preId;
// default delta snap number is 16
@ -322,7 +323,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
preSnapshotId = 0;
}
}
//If the volume is moved around, backup a full snapshot to secondary storage
if (volume.getLastPoolId() != null && !volume.getLastPoolId().equals(volume.getPoolId())) {
preSnapshotId = 0;
@ -359,24 +360,24 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
@DB
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_CREATE, eventDescription = "creating snapshot", async = true)
public SnapshotVO createSnapshot(Long volumeId, Long policyId, Long snapshotId, Account snapshotOwner) {
VolumeVO volume = _volsDao.findById(volumeId);
VolumeVO volume = _volsDao.findById(volumeId);
if (volume == null) {
throw new InvalidParameterValueException("No such volume exist");
}
if (volume.getState() != Volume.State.Ready) {
throw new InvalidParameterValueException("Volume is not in ready state");
}
SnapshotVO snapshot = null;
boolean backedUp = false;
UserVmVO uservm = null;
// does the caller have the authority to act on this volume
_accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume);
try {
Long poolId = volume.getPoolId();
if (poolId == null) {
throw new CloudRuntimeException("You cannot take a snapshot of a volume until it has been attached to an instance");
@ -387,7 +388,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (uservm != null && uservm.getType() != VirtualMachine.Type.User) {
throw new CloudRuntimeException("Can't take a snapshot on system vm ");
}
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
ClusterVO cluster = _clusterDao.findById(storagePool.getClusterId());
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(cluster.getId());
@ -407,7 +408,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " is associated with vm:" + userVm.getInstanceName() + " is in "
+ userVm.getState().toString() + " state");
}
if(userVm.getHypervisorType() == HypervisorType.VMware || userVm.getHypervisorType() == HypervisorType.KVM) {
List<SnapshotVO> activeSnapshots = _snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.Status.Creating, Snapshot.Status.CreatedOnPrimary, Snapshot.Status.BackingUp);
if(activeSnapshots.size() > 1)
@ -560,7 +561,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
} catch (Exception e) {
throw new CloudRuntimeException("downloadSnapshotsFromSwift failed due to " + e.toString());
}
}
private List<String> determineBackupUuids(final SnapshotVO snapshot) {
@ -630,9 +631,9 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
Long dcId = volume.getDataCenterId();
Long accountId = volume.getAccountId();
HostVO secHost = getSecHost(volumeId, volume.getDataCenterId());
String secondaryStoragePoolUrl = secHost.getStorageUrl();
String snapshotUuid = snapshot.getPath();
// In order to verify that the snapshot is not empty,
@ -647,12 +648,12 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
S3TO s3 = _s3Mgr.getS3TO();
checkObjectStorageConfiguration(swift, s3);
long prevSnapshotId = snapshot.getPrevSnapshotId();
if (prevSnapshotId > 0) {
prevSnapshot = _snapshotDao.findByIdIncludingRemoved(prevSnapshotId);
if ( prevSnapshot.getBackupSnapshotId() != null && swift == null) {
if (prevSnapshot.getVersion() != null && prevSnapshot.getVersion().equals("2.2")) {
if (prevSnapshot.getVersion() != null && prevSnapshot.getVersion().equals("2.2")) {
prevBackupUuid = prevSnapshot.getBackupSnapshotId();
prevSnapshotUuid = prevSnapshot.getPath();
}
@ -724,7 +725,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
private HostVO getSecHost(long volumeId, long dcId) {
Long id = _snapshotDao.getSecHostId(volumeId);
if ( id != null) {
if ( id != null) {
return _hostDao.findById(id);
}
return _storageMgr.getSecondaryStorageHost(dcId);
@ -743,7 +744,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
public void postCreateSnapshot(Long volumeId, Long snapshotId, Long policyId, boolean backedUp) {
Long userId = getSnapshotUserId();
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
if (snapshot != null && snapshot.isRecursive()) {
postCreateRecurringSnapshotForPolicy(userId, volumeId, snapshotId, policyId);
}
@ -783,13 +784,13 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (snapshotCheck == null) {
throw new InvalidParameterValueException("unable to find a snapshot with id " + snapshotId);
}
_accountMgr.checkAccess(caller, null, true, snapshotCheck);
if( !Status.BackedUp.equals(snapshotCheck.getStatus() ) ) {
throw new InvalidParameterValueException("Can't delete snapshotshot " + snapshotId + " due to it is not in BackedUp Status");
}
return deleteSnapshotInternal(snapshotId);
}
@ -943,7 +944,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
String snapshotTypeStr = cmd.getSnapshotType();
String intervalTypeStr = cmd.getIntervalType();
Map<String, String> tags = cmd.getTags();
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();
@ -959,8 +960,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
Filter searchFilter = new Filter(SnapshotVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<SnapshotVO> sb = _snapshotDao.createSearchBuilder();
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@ -971,7 +972,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("snapshotTypeEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.IN);
sb.and("snapshotTypeNEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.NEQ);
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
for (int count=0; count < tags.size(); count++) {
@ -990,7 +991,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (volumeId != null) {
sc.setParameters("volumeId", volumeId);
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.Snapshot.toString());
@ -1133,9 +1134,9 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (volume == null) {
throw new InvalidParameterValueException("Failed to create snapshot policy, unable to find a volume with id " + volumeId);
}
_accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume);
if (volume.getState() != Volume.State.Ready) {
throw new InvalidParameterValueException("VolumeId: " + volumeId + " is not in " + Volume.State.Ready + " state but " + volume.getState() + ". Cannot take snapshot.");
}
@ -1191,7 +1192,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (owner.getType() == Account.ACCOUNT_TYPE_PROJECT) {
message = "domain/project";
}
throw new InvalidParameterValueException("Max number of snapshots shouldn't exceed the " + message + " level snapshot limit");
}
@ -1227,14 +1228,15 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
@Override
public List<SnapshotPolicyVO> listPoliciesforVolume(ListSnapshotPoliciesCmd cmd) {
public Pair<List<? extends SnapshotPolicy>, Integer> listPoliciesforVolume(ListSnapshotPoliciesCmd cmd) {
Long volumeId = cmd.getVolumeId();
VolumeVO volume = _volsDao.findById(volumeId);
if (volume == null) {
throw new InvalidParameterValueException("Unable to find a volume with id " + volumeId);
}
_accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume);
return listPoliciesforVolume(cmd.getVolumeId());
Pair<List<SnapshotPolicyVO>, Integer> result = _snapshotPolicyDao.listAndCountByVolumeId(volumeId);
return new Pair<List<? extends SnapshotPolicy>, Integer>(result.first(), result.second());
}
@Override
@ -1352,7 +1354,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
@Override
public SnapshotVO allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException {
Account caller = UserContext.current().getCaller();
VolumeVO volume = _volsDao.findById(volumeId);
if (volume == null) {
throw new InvalidParameterValueException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist");
@ -1361,11 +1363,11 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (zone == null) {
throw new InvalidParameterValueException("Can't find zone by id " + volume.getDataCenterId());
}
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zone.getName());
}
if (volume.getState() != Volume.State.Ready) {
throw new InvalidParameterValueException("VolumeId: " + volumeId + " is not in " + Volume.State.Ready + " state but " + volume.getState() + ". Cannot take snapshot.");
}
@ -1376,7 +1378,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
throw new InvalidParameterValueException("VolumeId: " + volumeId + " is for System VM , Creating snapshot against System VM volumes is not supported");
}
}
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volume.getPoolId());
if (storagePoolVO == null) {
throw new InvalidParameterValueException("VolumeId: " + volumeId + " please attach this volume to a VM before create snapshot for it");
@ -1386,7 +1388,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (cluster != null && cluster.getHypervisorType() == HypervisorType.Ovm) {
throw new InvalidParameterValueException("Ovm won't support taking snapshot");
}
// Verify permissions
_accountMgr.checkAccess(caller, null, true, volume);
Type snapshotType = getSnapshotType(policyId);
@ -1397,7 +1399,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (snapshotType != Type.MANUAL){
String msg = "Snapshot resource limit exceeded for account id : " + owner.getId() + ". Failed to create recurring snapshots";
s_logger.warn(msg);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_UPDATE_RESOURCE_COUNT, 0L, 0L, msg,
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_UPDATE_RESOURCE_COUNT, 0L, 0L, msg,
"Snapshot resource limit exceeded for account id : " + owner.getId() + ". Failed to create recurring snapshots; please use updateResourceLimit to increase the limit");
}
throw e;
@ -1415,7 +1417,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
String snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;
// Create the Snapshot object and save it so we can return it to the
// user
// user
HypervisorType hypervisorType = this._volsDao.getHypervisorType(volumeId);
SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), null, snapshotName,
(short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), hypervisorType);
@ -1436,7 +1438,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
String value = configDao.getValue(Config.BackupSnapshotWait.toString());
_backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
@ -1533,7 +1535,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
return false;
}
@Override
public boolean canOperateOnVolume(VolumeVO volume) {
List<SnapshotVO> snapshots = _snapshotDao.listByStatus(volume.getId(), Status.Creating, Status.CreatedOnPrimary, Status.BackingUp);

View File

@ -27,6 +27,7 @@ import com.cloud.exception.DiscoveryException;
import com.cloud.storage.Swift;
import com.cloud.storage.SwiftVO;
import com.cloud.storage.VMTemplateSwiftVO;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Manager;
public interface SwiftManager extends Manager {
@ -50,7 +51,7 @@ public interface SwiftManager extends Manager {
Long chooseZoneForTmpltExtract(Long tmpltId);
List<SwiftVO> listSwifts(ListSwiftsCmd cmd);
Pair<List<SwiftVO>, Integer> listSwifts(ListSwiftsCmd cmd);
VMTemplateSwiftVO findByTmpltId(Long tmpltId);
}

View File

@ -50,6 +50,7 @@ import com.cloud.storage.dao.SwiftDao;
import com.cloud.storage.dao.VMTemplateHostDao;
import com.cloud.storage.dao.VMTemplateSwiftDao;
import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.SearchCriteria;
@ -242,7 +243,7 @@ public class SwiftManagerImpl implements SwiftManager {
if (swift == null) {
return null;
}
List<VMTemplateHostVO> tmpltHosts = _vmTmpltHostDao.listByOnlyTemplateId(tmpltId);
if (tmpltHosts != null) {
Collections.shuffle(tmpltHosts);
@ -260,13 +261,13 @@ public class SwiftManagerImpl implements SwiftManager {
}
@Override
public List<SwiftVO> listSwifts(ListSwiftsCmd cmd) {
public Pair<List<SwiftVO>, Integer> listSwifts(ListSwiftsCmd cmd) {
Filter searchFilter = new Filter(SwiftVO.class, "id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchCriteria<SwiftVO> sc = _swiftDao.createSearchCriteria();
if (cmd.getId() != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, cmd.getId());
}
return _swiftDao.search(sc, searchFilter);
return _swiftDao.searchAndCount(sc, searchFilter);
}

View File

@ -202,7 +202,7 @@ public class MockResourceManagerImpl implements ResourceManager, Manager {
* @see com.cloud.resource.ResourceService#listSwifts(com.cloud.api.commands.ListSwiftsCmd)
*/
@Override
public List<? extends Swift> listSwifts(ListSwiftsCmd cmd) {
public Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd) {
// TODO Auto-generated method stub
return null;
}

File diff suppressed because it is too large Load Diff

View File

@ -1332,6 +1332,7 @@ CREATE TABLE `cloud`.`alert` (
`last_sent` DATETIME NULL COMMENT 'Last time the alert was sent',
`resolved` DATETIME NULL COMMENT 'when the alert status was resolved (available memory no longer at critical level, etc.)',
PRIMARY KEY (`id`),
INDEX `last_sent` (`last_sent` DESC),
CONSTRAINT `uc_alert__uuid` UNIQUE (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

File diff suppressed because it is too large Load Diff

View File

@ -75,7 +75,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
# datastructure {'verb': {cmd': ['api', [params], doc, required=[]]}}
cache_verbs = precached_verbs
def __init__(self):
def __init__(self, pname):
self.program_name = pname
if os.path.exists(self.config_file):
config = self.read_config()
else:
@ -262,8 +263,9 @@ class CloudMonkeyShell(cmd.Cmd, object):
return
isAsync = isAsync and (self.asyncblock == "true")
if isAsync and 'jobid' in response[response.keys()[0]]:
jobId = response[response.keys()[0]]['jobid']
responsekey = filter(lambda x: 'response' in x, response.keys())[0]
if isAsync and 'jobid' in response[responsekey]:
jobId = response[responsekey]['jobid']
command = "queryAsyncJobResult"
requests = {'jobid': jobId}
timeout = int(self.timeout)
@ -282,7 +284,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
jobstatus = result['jobstatus']
if jobstatus == 2:
jobresult = result["jobresult"]
self.print_shell("Async query failed for jobid=",
self.print_shell("\rAsync query failed for jobid",
jobId, "\nError", jobresult["errorcode"],
jobresult["errortext"])
return
@ -293,7 +295,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
timeout = timeout - pollperiod
progress += 1
logger.debug("job: %s to timeout in %ds" % (jobId, timeout))
self.print_shell("Error:", "Async query timeout for jobid=", jobId)
self.print_shell("Error:", "Async query timeout for jobid", jobId)
return response
@ -306,7 +308,19 @@ class CloudMonkeyShell(cmd.Cmd, object):
return None
return api_mod
def pipe_runner(self, args):
if args.find(' |') > -1:
pname = self.program_name
if '.py' in pname:
pname = "python " + pname
self.do_shell("%s %s" % (pname, args))
return True
return False
def default(self, args):
if self.pipe_runner(args):
return
lexp = shlex.shlex(args.strip())
lexp.whitespace = " "
lexp.whitespace_split = True
@ -387,7 +401,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
self.cache_verbs[verb][subject][1])
search_string = text
autocompletions.append("filter=")
if self.tabularize == "true":
autocompletions.append("filter=")
return [s for s in autocompletions if s.startswith(search_string)]
def do_api(self, args):
@ -504,22 +519,21 @@ def main():
for rule in grammar:
def add_grammar(rule):
def grammar_closure(self, args):
if '|' in args: # FIXME: Consider parsing issues
prog_name = sys.argv[0]
if '.py' in prog_name:
prog_name = "python " + prog_name
self.do_shell("%s %s %s" % (prog_name, rule, args))
if self.pipe_runner("%s %s" % (rule, args)):
return
try:
args_partition = args.partition(" ")
res = self.cache_verbs[rule][args_partition[0]]
cmd = res[0]
helpdoc = res[2]
args = args_partition[2]
except KeyError, e:
self.print_shell("Error: invalid %s api arg" % rule, e)
return
if ' --help' in args or ' -h' in args:
self.print_shell(res[2])
self.print_shell(helpdoc)
return
self.default(res[0] + " " + args_partition[2])
self.default("%s %s" % (cmd, args))
return grammar_closure
grammar_handler = add_grammar(rule)
@ -527,7 +541,7 @@ def main():
grammar_handler.__name__ = 'do_' + rule
setattr(self, grammar_handler.__name__, grammar_handler)
shell = CloudMonkeyShell()
shell = CloudMonkeyShell(sys.argv[0])
if len(sys.argv) > 1:
shell.onecmd(' '.join(sys.argv[1:]))
else:

View File

@ -40,9 +40,9 @@ config_fields = {'host': 'localhost', 'port': '8080',
os.path.expanduser('~/.cloudmonkey_history')}
# Add verbs in grammar
grammar = ['create', 'list', 'delete', 'update',
grammar = ['create', 'list', 'delete', 'update', 'lock',
'enable', 'activate', 'disable', 'add', 'remove',
'attach', 'detach', 'associate', 'generate', 'ldap',
'attach', 'detach', 'associate', 'disassociate', 'generate', 'ldap',
'assign', 'authorize', 'change', 'register', 'configure',
'start', 'restart', 'reboot', 'stop', 'reconnect',
'cancel', 'destroy', 'revoke', 'mark', 'reset',

View File

@ -53,7 +53,7 @@ setup(
include_package_data = True,
zip_safe = False,
classifiers = [
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",

View File

@ -12,7 +12,7 @@
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-devcloud-kvm</artifactId>
<name>Apache CloudStack Developer Tools</name>
<name>Apache CloudStack DevCloud-KVM</name>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.cloudstack</groupId>
@ -27,6 +27,14 @@
<version>5.1.21</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-developer</artifactId>
<version>${project.version}</version>
<type>pom</type>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>

View File

@ -37,4 +37,4 @@ INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'se
UPDATE `cloud`.`configuration` SET value='10' where name = 'storage.overprovisioning.factor';
UPDATE `cloud`.`configuration` SET value='10' where name = 'cpu.overprovisioning.factor';
UPDATE `cloud`.`configuration` SET value='10' where name = 'mem.overprovisioning.factor';
UPDATE `cloud`.`vm_template` SET unique_name="tiny Linux",name="tiny Linux",url="https://github.com/downloads/bhaisaab/incubator-cloudstack/ttylinux_pv.vhd",checksum="046e134e642e6d344b34648223ba4bc1",display_text="tiny Linux" where id=5;
UPDATE `cloud`.`vm_template` SET unique_name="tiny Linux",name="tiny Linux",url="http://people.apache.org/~bhaisaab/vms/ttylinux_pv.vhd",checksum="046e134e642e6d344b34648223ba4bc1",display_text="tiny Linux" where id=5;

View File

@ -0,0 +1,121 @@
# 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.
#
{
"zones": [
{
"name": "DevCloud0",
"physical_networks": [
{
"broadcastdomainrange": "Zone",
"name": "test-network",
"traffictypes": [
{
"typ": "Guest"
},
{
"typ": "Management"
}
],
"providers": [
{
"broadcastdomainrange": "ZONE",
"name": "VirtualRouter"
},
{
"broadcastdomainrange": "Pod",
"name": "SecurityGroupProvider"
}
]
}
],
"dns2": "4.4.4.4",
"dns1": "8.8.8.8",
"securitygroupenabled": "true",
"localstorageenabled": "true",
"networktype": "Basic",
"pods": [
{
"endip": "192.168.56.220",
"name": "test00",
"startip": "192.168.56.200",
"guestIpRanges": [
{
"startip": "192.168.56.100",
"endip": "192.168.56.199",
"netmask": "255.255.255.0",
"gateway": "192.168.56.1"
}
],
"netmask": "255.255.255.0",
"clusters": [
{
"clustername": "test000",
"hypervisor": "XenServer",
"hosts": [
{
"username": "root",
"url": "http://192.168.56.10/",
"password": "password"
}
],
"clustertype": "CloudManaged"
}
],
"gateway": "192.168.56.1"
}
],
"internaldns1": "192.168.56.1",
"secondaryStorages": [
{
"url": "nfs://192.168.56.10:/opt/storage/secondary"
}
]
}
],
"logger": [
{
"name": "TestClient",
"file": "/tmp/testclient.log"
},
{
"name": "TestCase",
"file": "/tmp/testcase.log"
}
],
"mgtSvr": [
{
"mgtSvrIp": "192.168.56.10",
"port": 8096
}
],
"dbSvr":
{
"dbSvr": "127.0.0.1",
"port": 3306,
"user": "cloud",
"passwd": "cloud",
"db": "cloud"
}
"globalConfig": [
{
"name": "host",
"value": "192.168.56.10"
}
]
}

View File

@ -12,7 +12,7 @@
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-devcloud</artifactId>
<name>Apache CloudStack Developer Tools</name>
<name>Apache CloudStack DevCloud</name>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.cloudstack</groupId>
@ -27,6 +27,14 @@
<version>5.1.21</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-developer</artifactId>
<version>${project.version}</version>
<type>pom</type>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>

View File

@ -5778,6 +5778,10 @@ label.error {
height: 223px;
}
.multi-wizard.instance-wizard .select-network.no-add-network .select table .select-container {
height: 282px;
}
.multi-wizard.instance-wizard .select-network .select.new-network table .select-container {
height: 29px;
overflow: visible;
@ -5802,6 +5806,10 @@ label.error {
margin: -17px 0 0;
}
.multi-wizard.instance-wizard .select-network.no-add-network .select.new-network {
display: none !important;
}
.multi-wizard.instance-wizard .select-network .main-desc {
width: 252px;
top: 12px;
@ -5851,6 +5859,10 @@ label.error {
margin: 7px 0px 7px 7px;
}
.multi-wizard.instance-wizard .select-network.no-add-network .select-vpc {
visibility: hidden !important;
}
.multi-wizard.instance-wizard .select-network .select-vpc select {
width: 124px;
}

View File

@ -959,7 +959,7 @@ under the License.
<div class="button refresh" id="refresh_button">
<span><fmt:message key="label.refresh"/></span>
</div>
<div id="update_ssl_button" class="button action main-action reduced-hide lock">
<div id="update_ssl_button" class="button action main-action reduced-hide lock" title="Updates your Console Proxy SSL Certificate">
<span class="icon">&nbsp;</span>
<span><fmt:message key="label.update.ssl.cert"/></span>
</div>

View File

@ -642,12 +642,16 @@
},
vmLimit: {
label: 'label.instance.limits',
isEditable: function(context) {
isEditable: function(context) {
if(context.accounts == undefined)
return false;
else {
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
return true;
else
return false;
}
} }
},
ipLimit: {
label: 'label.ip.limits',

View File

@ -1293,11 +1293,11 @@
}
}
//hide/show service fields ***** (end) *****
//show LB InlineMode dropdown only when (1)LB Service is checked (2)Service Provider is F5
if((args.$form.find('.form-item[rel=\"service.Lb.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true)
&&(args.$form.find('.form-item[rel=\"service.Lb.provider\"]').find('select').val() == 'F5BigIp') && ( args.$form.find('.form-item[rel=\"service.Firewall.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true) && (args.$form.find('.form-item[rel=\"service.Firewall.provider\"]').find('select').val() == 'JuniperSRX')) {
//show LB InlineMode dropdown only when (1)LB service is checked and LB service provider is F5BigIp (2)Firewall service is checked and Firewall service provider is JuniperSRX
if((args.$form.find('.form-item[rel=\"service.Lb.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true) && (args.$form.find('.form-item[rel=\"service.Lb.provider\"]').find('select').val() == 'F5BigIp') &&
(args.$form.find('.form-item[rel=\"service.Firewall.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true) && (args.$form.find('.form-item[rel=\"service.Firewall.provider\"]').find('select').val() == 'JuniperSRX'))
{
args.$form.find('.form-item[rel=\"service.Lb.inlineModeDropdown\"]').css('display', 'inline-block');
}
else {
@ -1325,10 +1325,10 @@
args.$form.find('.form-item[rel=\"service.Lb.elasticLbCheckbox\"]').find('input[type=checkbox]').attr('checked', false);
}
//show Elastic IP checkbox only when (1)StaticNat Service is checked (2)Service Provider is Netscaler (3)Guest IP Type is Shared
//show Elastic IP checkbox only when (1)StaticNat service is checked (2)StaticNat service provider is Netscaler
if((args.$form.find('.form-item[rel=\"service.StaticNat.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true)
&&(args.$form.find('.form-item[rel=\"service.StaticNat.provider\"]').find('select').val() == 'Netscaler')
&&(args.$form.find('.form-item[rel=\"guestIpType\"]').find('select').val() == 'Shared')) {
) {
args.$form.find('.form-item[rel=\"service.StaticNat.elasticIpCheckbox\"]').css('display', 'inline-block');
}
else {

View File

@ -16,7 +16,7 @@
// under the License.
(function($, cloudStack) {
var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, featuredIsoObjs, community;
var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, featuredIsoObjs, community, networkObjs;
var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj;
var step5ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group'
@ -40,6 +40,33 @@
!data.vpcid;
},
// Runs when advanced SG-enabled zone is run, before
// the security group step
//
// -- if it returns false, then 'Select Security Group' is skipped.
//
advSGFilter: function(args) {
var selectedNetworks;
if ($.isArray(args.data['my-networks'])) {
selectedNetworks = $(args.data['my-networks']).map(function(index, myNetwork) {
return $.grep(networkObjs, function(networkObj) {
return networkObj.id == myNetwork;
});
});
} else {
selectedNetworks = $.grep(networkObjs, function(networkObj) {
return networkObj.id == args.data['my-networks'];
});
}
return $.grep(selectedNetworks, function(network) {
return $.grep(network.service, function(service) {
return service.name == 'SecurityGroup';
}).length;
}).length;
},
// Data providers for each wizard step
steps: [
@ -284,6 +311,7 @@
$networkStep.find("#from_instance_page_2").show();
$networkStep.find("#from_vpc_tier").text("");
$networkStep.find("#from_vpc_tier").hide();
$networkStepContainer.removeClass('next-use-security-groups');
} else { // Advanced SG-enabled zone
step5ContainerType = 'select-advanced-sg';
}
@ -328,7 +356,8 @@
if(step5ContainerType == 'select-network' || step5ContainerType == 'select-advanced-sg') {
var defaultNetworkArray = [], optionalNetworkArray = [];
var networkData = {
zoneId: args.currentData.zoneid
zoneId: args.currentData.zoneid,
canusefordeploy: true
};
// step5ContainerType of Advanced SG-enabled zone is 'select-security-group', so won't come into this block
@ -345,7 +374,7 @@
networkData.account = g_account;
}
var networkObjs, vpcObjs;
var vpcObjs;
//listVPCs without account/domainid/listAll parameter will return only VPCs belonging to the current login. That's what should happen in Instances page's VM Wizard.
//i.e. If the current login is root-admin, do not show VPCs belonging to regular-user/domain-admin in Instances page's VM Wizard.
@ -363,6 +392,18 @@
async: false,
success: function(json) {
networkObjs = json.listnetworksresponse.network ? json.listnetworksresponse.network : [];
if(networkObjs.length > 0) {
for(var i = 0; i < networkObjs.length; i++) {
var networkObj = networkObjs[i];
var serviceObjArray = networkObj.service;
for(var k = 0; k < serviceObjArray.length; k++) {
if(serviceObjArray[k].name == "SecurityGroup") {
networkObjs[i].type = networkObjs[i].type + ' (sg)';
}
}
}
}
}
});
@ -384,15 +425,21 @@
});
//get network offerings (end) ***
$networkStepContainer.removeClass('repeat next-use-security-groups');
if (step5ContainerType == 'select-advanced-sg') {
$networkStepContainer.addClass('repeat next-use-security-groups');
// Add guest network is disabled
$networkStepContainer.find('.select-network').addClass('no-add-network');
} else {
$networkStepContainer.find('.select-network').removeClass('no-add-network');
}
args.response.success({
type: 'select-network',
data: {
myNetworks: [], //not used any more
sharedNetworks: networkObjs,
data: {
networkObjs: networkObjs,
securityGroups: [],
networkOfferings: networkOfferingObjs,
vpcs: vpcObjs
@ -423,9 +470,8 @@
});
args.response.success({
type: 'select-security-group',
data: {
myNetworks: [], //not used any more
sharedNetworks: [],
data: {
networkObjs: [],
securityGroups: securityGroupArray,
networkOfferings: [],
vpcs: []
@ -436,9 +482,8 @@
else if(step5ContainerType == 'nothing-to-select') {
args.response.success({
type: 'nothing-to-select',
data: {
myNetworks: [], //not used any more
sharedNetworks: [],
data: {
networkObjs: [],
securityGroups: [],
networkOfferings: [],
vpcs: []

View File

@ -1026,7 +1026,7 @@
createForm: {
desc: 'message.enter.token',
fields: {
projectid: { label: 'label.project.id', validation: { required: true, docID: 'helpEnterTokenProjectID' }},
projectid: { label: 'label.project.id', validation: { required: true}, docID: 'helpEnterTokenProjectID' },
token: { label: 'label.token', docID: 'helpEnterTokenToken', validation: { required: true }}
}
},

View File

@ -1322,6 +1322,13 @@
networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
if (networkOfferingObjs != null && networkOfferingObjs.length > 0) {
for (var i = 0; i < networkOfferingObjs.length; i++) {
if(args.scope=="account-specific" && args.context.zones[0].securitygroupsenabled == true) { //BUG - CLOUDSTACK-1063
var serviceObjArray = networkOfferingObjs[i].name;
if(serviceObjArray == "DefaultSharedNetworkOfferingWithSGService"){
continue;
}
}
//comment out the following 12 lines because of CS-16718
/*

View File

@ -636,7 +636,7 @@
// My networks
$step.find('.my-networks .select-container').append(
makeSelects('my-networks', $.merge(args.data.myNetworks, args.data.sharedNetworks), {
makeSelects('my-networks', args.data.networkObjs, {
name: 'name',
desc: 'type',
id: 'id'
@ -821,6 +821,16 @@
cloudStack.dialog.notice({ message: 'message.step.4.continue' });
return false;
}
if ($activeStep.hasClass('next-use-security-groups')) {
var advSGFilter = args.advSGFilter({
data: cloudStack.serializeForm($form)
});
if (!advSGFilter) {
showStep(6);
}
}
}
//step 6 - review (spcifiy displyname, group as well)
@ -850,8 +860,19 @@
// Previous button
if ($target.closest('div.button.previous').size()) {
var index = $steps.filter(':visible').index();
if (index) showStep(index);
var $step = $steps.filter(':visible');
var $networkStep = $steps.filter('.network');
var index = $step.index();
$networkStep.removeClass('next-use-security-groups');
if (index) {
if (index == $steps.size() - 1 && $networkStep.hasClass('next-use-security-groups')) {
showStep(5);
} else {
showStep(index);
}
}
return false;
}

View File

@ -16,8 +16,11 @@
// under the License.
package com.cloud.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
public class IteratorUtil {
public static <T> Iterable<T> enumerationAsIterable(final Enumeration<T> e) {
@ -51,4 +54,11 @@ public class IteratorUtil {
}
};
}
public static
<T extends Comparable<? super T>> List<T> asSortedList(Collection<T> c) {
List<T> list = new ArrayList<T>(c);
java.util.Collections.sort(list);
return list;
}
}

View File

@ -19,7 +19,10 @@ package com.cloud.utils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.cloud.utils.exception.CloudRuntimeException;
@ -87,26 +90,39 @@ public class ReflectUtil {
return isAsync;
}
// Returns all fields across the base class for a cmd
public static Field[] getAllFieldsForClass(Class<?> cmdClass,
Class<?>[] searchClasses) {
Field[] fields = cmdClass.getDeclaredFields();
// Returns all fields until a base class for a cmd class
public static List<Field> getAllFieldsForClass(Class<?> cmdClass,
Class<?> baseClass) {
List<Field> fields = new ArrayList<Field>();
Collections.addAll(fields, cmdClass.getDeclaredFields());
Class<?> superClass = cmdClass.getSuperclass();
while (baseClass.isAssignableFrom(superClass)) {
Field[] superClassFields = superClass.getDeclaredFields();
if (superClassFields != null)
Collections.addAll(fields, superClassFields);
superClass = superClass.getSuperclass();
}
return fields;
}
// Returns all unique fields except excludeClasses for a cmd class
public static Set<Field> getAllFieldsForClass(Class<?> cmdClass,
Class<?>[] excludeClasses) {
Set<Field> fields = new HashSet<Field>();
Collections.addAll(fields, cmdClass.getDeclaredFields());
Class<?> superClass = cmdClass.getSuperclass();
while (superClass != null && superClass != Object.class) {
String superName = superClass.getName();
for (Class<?> baseClass: searchClasses) {
if(!baseClass.isAssignableFrom(superClass))
continue;
if (!superName.equals(baseClass.getName())) {
Field[] superClassFields = superClass.getDeclaredFields();
if (superClassFields != null) {
Field[] tmpFields = new Field[fields.length + superClassFields.length];
System.arraycopy(fields, 0, tmpFields, 0, fields.length);
System.arraycopy(superClassFields, 0, tmpFields, fields.length, superClassFields.length);
fields = tmpFields;
}
}
boolean isNameEqualToSuperName = false;
for (Class<?> baseClass: excludeClasses)
if (superName.equals(baseClass.getName()))
isNameEqualToSuperName = true;
if (!isNameEqualToSuperName) {
Field[] superClassFields = superClass.getDeclaredFields();
if (superClassFields != null)
Collections.addAll(fields, superClassFields);
}
superClass = superClass.getSuperclass();
}

View File

@ -57,6 +57,9 @@ public interface GenericDao<T, ID extends Serializable> {
// Finds one unique VO using uuid
T findByUuid(String uuid);
// Finds one unique VO using uuid including removed entities
T findByUuidIncludingRemoved(String uuid);
/**
* @return VO object ready to be used for update. It won't have any fields filled in.

View File

@ -921,6 +921,14 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
return findOneBy(sc);
}
@Override @DB(txn=false)
@SuppressWarnings("unchecked")
public T findByUuidIncludingRemoved(final String uuid) {
SearchCriteria<T> sc = createSearchCriteria();
sc.addAnd("uuid", SearchCriteria.Op.EQ, uuid);
return findOneIncludingRemovedBy(sc);
}
@Override @DB(txn=false)
public T findByIdIncludingRemoved(ID id) {
return findById(id, true, null);

View File

@ -195,51 +195,65 @@ public class Script implements Callable<String> {
}
Task task = null;
if (interpreter.drain()) {
if (interpreter != null && interpreter.drain()) {
task = new Task(interpreter, ir);
s_executors.execute(task);
}
while (true) {
try {
if (_process.waitFor() == 0) {
_logger.debug("Execution is successful.");
while (true) {
try {
if (_process.waitFor() == 0) {
_logger.debug("Execution is successful.");
if (interpreter != null) {
return interpreter.drain() ? task.getResult() : interpreter.interpret(ir);
} else {
// null return is ok apparently
return (_process.exitValue() == 0) ? "Ok" : "Failed, exit code " + _process.exitValue();
}
} else {
break;
}
} catch (InterruptedException e) {
if (!_isTimeOut) {
/*
* This is not timeout, we are interrupted by others,
* continue
*/
_logger.debug("We are interrupted but it's not a timeout, just continue");
continue;
}
return interpreter.drain() ? task.getResult() : interpreter.interpret(ir);
} else {
break;
}
} catch (InterruptedException e) {
if (!_isTimeOut) {
/* This is not timeout, we are interrupted by others, continue */
_logger.debug("We are interrupted but it's not a timeout, just continue");
continue;
}
TimedOutLogger log = new TimedOutLogger(_process);
Task timedoutTask = new Task(log, ir);
TimedOutLogger log = new TimedOutLogger(_process);
Task timedoutTask = new Task(log, ir);
timedoutTask.run();
if (!_passwordCommand) {
_logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult());
} else {
_logger.warn("Timed out: " + buildCommandLine(command));
}
timedoutTask.run();
if (!_passwordCommand) {
_logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult());
} else {
_logger.warn("Timed out: " + buildCommandLine(command));
}
return ERR_TIMEOUT;
} finally {
if (future != null) {
future.cancel(false);
}
Thread.interrupted();
}
}
return ERR_TIMEOUT;
} finally {
if (future != null) {
future.cancel(false);
}
Thread.interrupted();
}
}
_logger.debug("Exit value is " + _process.exitValue());
_logger.debug("Exit value is " + _process.exitValue());
BufferedReader reader = new BufferedReader(new InputStreamReader(_process.getInputStream()), 128);
String error = interpreter.processError(reader);
String error;
if (interpreter != null) {
error = interpreter.processError(reader);
}
else {
error = "Non zero exit code : " + _process.exitValue();
}
if (_logger.isDebugEnabled()) {
_logger.debug(error);
}