mirror of https://github.com/apache/cloudstack.git
Removed trailing spaces
This commit is contained in:
parent
0232906708
commit
62e9273581
|
|
@ -1,26 +1,26 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api.storage;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
public class CreateVolumeOVAAnswer extends Answer {
|
||||
public CreateVolumeOVAAnswer(CreateVolumeOVACommand cmd, boolean result, String details) {
|
||||
super(cmd, result, details);
|
||||
}
|
||||
|
||||
}
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api.storage;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
public class CreateVolumeOVAAnswer extends Answer {
|
||||
public CreateVolumeOVAAnswer(CreateVolumeOVACommand cmd, boolean result, String details) {
|
||||
super(cmd, result, details);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,60 +1,60 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api.storage;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.to.StorageFilerTO;
|
||||
import com.cloud.storage.StoragePool;
|
||||
|
||||
public class CreateVolumeOVACommand extends Command {
|
||||
String secUrl;
|
||||
String volPath;
|
||||
String volName;
|
||||
StorageFilerTO pool;
|
||||
|
||||
public CreateVolumeOVACommand() {
|
||||
}
|
||||
|
||||
public CreateVolumeOVACommand(String secUrl, String volPath, String volName, StoragePool pool, int wait) {
|
||||
this.secUrl = secUrl;
|
||||
this.volPath = volPath;
|
||||
this.volName = volName;
|
||||
this.pool = new StorageFilerTO(pool);
|
||||
setWait(wait);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getVolPath() {
|
||||
return this.volPath;
|
||||
}
|
||||
|
||||
public String getVolName() {
|
||||
return this.volName;
|
||||
}
|
||||
|
||||
public String getSecondaryStorageUrl() {
|
||||
return this.secUrl;
|
||||
}
|
||||
|
||||
public StorageFilerTO getPool() {
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api.storage;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.to.StorageFilerTO;
|
||||
import com.cloud.storage.StoragePool;
|
||||
|
||||
public class CreateVolumeOVACommand extends Command {
|
||||
String secUrl;
|
||||
String volPath;
|
||||
String volName;
|
||||
StorageFilerTO pool;
|
||||
|
||||
public CreateVolumeOVACommand() {
|
||||
}
|
||||
|
||||
public CreateVolumeOVACommand(String secUrl, String volPath, String volName, StoragePool pool, int wait) {
|
||||
this.secUrl = secUrl;
|
||||
this.volPath = volPath;
|
||||
this.volName = volName;
|
||||
this.pool = new StorageFilerTO(pool);
|
||||
setWait(wait);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getVolPath() {
|
||||
return this.volPath;
|
||||
}
|
||||
|
||||
public String getVolName() {
|
||||
return this.volName;
|
||||
}
|
||||
|
||||
public String getSecondaryStorageUrl() {
|
||||
return this.secUrl;
|
||||
}
|
||||
|
||||
public StorageFilerTO getPool() {
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api.storage;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
public class PrepareOVAPackingAnswer extends Answer {
|
||||
public PrepareOVAPackingAnswer(PrepareOVAPackingCommand cmd, boolean result, String details) {
|
||||
super(cmd, result, details);
|
||||
}
|
||||
|
||||
}
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api.storage;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
public class PrepareOVAPackingAnswer extends Answer {
|
||||
public PrepareOVAPackingAnswer(PrepareOVAPackingCommand cmd, boolean result, String details) {
|
||||
super(cmd, result, details);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +1,46 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api.storage;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class PrepareOVAPackingCommand extends Command {
|
||||
private String templatePath;
|
||||
private String secUrl;
|
||||
|
||||
public PrepareOVAPackingCommand() {
|
||||
}
|
||||
|
||||
public PrepareOVAPackingCommand(String secUrl, String templatePath) {
|
||||
this.secUrl = secUrl;
|
||||
this.templatePath = templatePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getTemplatePath() {
|
||||
return this.templatePath;
|
||||
}
|
||||
|
||||
public String getSecondaryStorageUrl() {
|
||||
return this.secUrl;
|
||||
}
|
||||
|
||||
}
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api.storage;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class PrepareOVAPackingCommand extends Command {
|
||||
private String templatePath;
|
||||
private String secUrl;
|
||||
|
||||
public PrepareOVAPackingCommand() {
|
||||
}
|
||||
|
||||
public PrepareOVAPackingCommand(String secUrl, String templatePath) {
|
||||
this.secUrl = secUrl;
|
||||
this.templatePath = templatePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getTemplatePath() {
|
||||
return this.templatePath;
|
||||
}
|
||||
|
||||
public String getSecondaryStorageUrl() {
|
||||
return this.secUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,34 @@
|
|||
// 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.exception;
|
||||
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class AffinityConflictException extends CloudRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = SerialVersionUID.AffinityConflictException;
|
||||
|
||||
public AffinityConflictException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public AffinityConflictException(String message, Throwable th) {
|
||||
super(message, th);
|
||||
}
|
||||
|
||||
}
|
||||
// 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.exception;
|
||||
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class AffinityConflictException extends CloudRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = SerialVersionUID.AffinityConflictException;
|
||||
|
||||
public AffinityConflictException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public AffinityConflictException(String message, Throwable th) {
|
||||
super(message, th);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
// 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.affinity;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
public interface AffinityGroup extends ControlledEntity, InternalIdentity, Identity {
|
||||
|
||||
String getName();
|
||||
|
||||
String getDescription();
|
||||
|
||||
String getType();
|
||||
|
||||
ACLType getAclType();
|
||||
|
||||
}
|
||||
// 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.affinity;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
public interface AffinityGroup extends ControlledEntity, InternalIdentity, Identity {
|
||||
|
||||
String getName();
|
||||
|
||||
String getDescription();
|
||||
|
||||
String getType();
|
||||
|
||||
ACLType getAclType();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,88 +1,88 @@
|
|||
// 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.affinity;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public interface AffinityGroupProcessor extends Adapter {
|
||||
|
||||
/**
|
||||
* process() is called to apply any user preferences to the deployment plan
|
||||
* and avoid set for the given VM placement.
|
||||
*
|
||||
* @param vm
|
||||
* virtual machine.
|
||||
* @param plan
|
||||
* deployment plan that tells you where it's being deployed to.
|
||||
* @param avoid
|
||||
* avoid these data centers, pods, clusters, or hosts.
|
||||
*/
|
||||
void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException;
|
||||
|
||||
/**
|
||||
* getType() should return the affinity/anti-affinity group being
|
||||
* implemented
|
||||
*
|
||||
* @return String Affinity/Anti-affinity type
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* check() is called to see if the planned destination fits the group
|
||||
* requirements
|
||||
*
|
||||
* @param vm
|
||||
* virtual machine.
|
||||
* @param plannedDestination
|
||||
* deployment destination where VM is planned to be deployed
|
||||
*/
|
||||
boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination) throws AffinityConflictException;
|
||||
|
||||
/**
|
||||
* isAdminControlledGroup() should return true if the affinity/anti-affinity
|
||||
* group can only be operated on[create/delete/modify] by the Admin
|
||||
*
|
||||
* @return boolean true/false
|
||||
*/
|
||||
boolean isAdminControlledGroup();
|
||||
|
||||
/**
|
||||
* canBeSharedDomainWide() should return true if the affinity/anti-affinity
|
||||
* group can be created for a domain and shared by all accounts under the
|
||||
* domain.
|
||||
*
|
||||
* @return boolean true/false
|
||||
*/
|
||||
boolean canBeSharedDomainWide();
|
||||
|
||||
/**
|
||||
* subDomainAccess() should return true if the affinity/anti-affinity group
|
||||
* can be created for a domain and used by the sub-domains. If true, all
|
||||
* accounts under the sub-domains can see this group and use it.
|
||||
*
|
||||
* @return boolean true/false
|
||||
*/
|
||||
boolean subDomainAccess();
|
||||
|
||||
void handleDeleteGroup(AffinityGroup group);
|
||||
|
||||
// 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.affinity;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public interface AffinityGroupProcessor extends Adapter {
|
||||
|
||||
/**
|
||||
* process() is called to apply any user preferences to the deployment plan
|
||||
* and avoid set for the given VM placement.
|
||||
*
|
||||
* @param vm
|
||||
* virtual machine.
|
||||
* @param plan
|
||||
* deployment plan that tells you where it's being deployed to.
|
||||
* @param avoid
|
||||
* avoid these data centers, pods, clusters, or hosts.
|
||||
*/
|
||||
void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException;
|
||||
|
||||
/**
|
||||
* getType() should return the affinity/anti-affinity group being
|
||||
* implemented
|
||||
*
|
||||
* @return String Affinity/Anti-affinity type
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* check() is called to see if the planned destination fits the group
|
||||
* requirements
|
||||
*
|
||||
* @param vm
|
||||
* virtual machine.
|
||||
* @param plannedDestination
|
||||
* deployment destination where VM is planned to be deployed
|
||||
*/
|
||||
boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination) throws AffinityConflictException;
|
||||
|
||||
/**
|
||||
* isAdminControlledGroup() should return true if the affinity/anti-affinity
|
||||
* group can only be operated on[create/delete/modify] by the Admin
|
||||
*
|
||||
* @return boolean true/false
|
||||
*/
|
||||
boolean isAdminControlledGroup();
|
||||
|
||||
/**
|
||||
* canBeSharedDomainWide() should return true if the affinity/anti-affinity
|
||||
* group can be created for a domain and shared by all accounts under the
|
||||
* domain.
|
||||
*
|
||||
* @return boolean true/false
|
||||
*/
|
||||
boolean canBeSharedDomainWide();
|
||||
|
||||
/**
|
||||
* subDomainAccess() should return true if the affinity/anti-affinity group
|
||||
* can be created for a domain and used by the sub-domains. If true, all
|
||||
* accounts under the sub-domains can see this group and use it.
|
||||
*
|
||||
* @return boolean true/false
|
||||
*/
|
||||
boolean subDomainAccess();
|
||||
|
||||
void handleDeleteGroup(AffinityGroup group);
|
||||
|
||||
}
|
||||
|
|
@ -1,82 +1,82 @@
|
|||
// 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.affinity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public interface AffinityGroupService {
|
||||
|
||||
/**
|
||||
* Creates an affinity/anti-affinity group for the given account/domain.
|
||||
*
|
||||
* @param account
|
||||
* @param domainId
|
||||
* @param name
|
||||
* @param type
|
||||
* @param description
|
||||
* @return AffinityGroup
|
||||
*/
|
||||
|
||||
AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName, String affinityGroupType, String description);
|
||||
|
||||
/**
|
||||
* Creates an affinity/anti-affinity group.
|
||||
*
|
||||
* @param affinityGroupId
|
||||
* @param account
|
||||
* @param domainId
|
||||
* @param affinityGroupName
|
||||
*/
|
||||
boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName);
|
||||
|
||||
/** Lists Affinity Groups in your account
|
||||
* @param account
|
||||
* @param domainId
|
||||
* @param affinityGroupId
|
||||
* @param affinityGroupName
|
||||
* @param affinityGroupType
|
||||
* @param vmId
|
||||
* @param startIndex
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
Pair<List<? extends AffinityGroup>, Integer> listAffinityGroups(Long affinityGroupId, String affinityGroupName, String affinityGroupType, Long vmId, Long startIndex,
|
||||
Long pageSize);
|
||||
|
||||
/**
|
||||
* List group types available in deployment
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<String> listAffinityGroupTypes();
|
||||
|
||||
AffinityGroup getAffinityGroup(Long groupId);
|
||||
|
||||
UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds);
|
||||
|
||||
boolean isAffinityGroupProcessorAvailable(String affinityGroupType);
|
||||
|
||||
boolean isAdminControlledGroup(AffinityGroup group);
|
||||
|
||||
boolean isAffinityGroupAvailableInDomain(long affinityGroupId, long domainId);
|
||||
|
||||
AffinityGroup createAffinityGroupInternal(String account, Long domainId, String affinityGroupName, String affinityGroupType, String description);
|
||||
|
||||
}
|
||||
// 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.affinity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public interface AffinityGroupService {
|
||||
|
||||
/**
|
||||
* Creates an affinity/anti-affinity group for the given account/domain.
|
||||
*
|
||||
* @param account
|
||||
* @param domainId
|
||||
* @param name
|
||||
* @param type
|
||||
* @param description
|
||||
* @return AffinityGroup
|
||||
*/
|
||||
|
||||
AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName, String affinityGroupType, String description);
|
||||
|
||||
/**
|
||||
* Creates an affinity/anti-affinity group.
|
||||
*
|
||||
* @param affinityGroupId
|
||||
* @param account
|
||||
* @param domainId
|
||||
* @param affinityGroupName
|
||||
*/
|
||||
boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName);
|
||||
|
||||
/** Lists Affinity Groups in your account
|
||||
* @param account
|
||||
* @param domainId
|
||||
* @param affinityGroupId
|
||||
* @param affinityGroupName
|
||||
* @param affinityGroupType
|
||||
* @param vmId
|
||||
* @param startIndex
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
Pair<List<? extends AffinityGroup>, Integer> listAffinityGroups(Long affinityGroupId, String affinityGroupName, String affinityGroupType, Long vmId, Long startIndex,
|
||||
Long pageSize);
|
||||
|
||||
/**
|
||||
* List group types available in deployment
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<String> listAffinityGroupTypes();
|
||||
|
||||
AffinityGroup getAffinityGroup(Long groupId);
|
||||
|
||||
UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds);
|
||||
|
||||
boolean isAffinityGroupProcessorAvailable(String affinityGroupType);
|
||||
|
||||
boolean isAdminControlledGroup(AffinityGroup group);
|
||||
|
||||
boolean isAffinityGroupAvailableInDomain(long affinityGroupId, long domainId);
|
||||
|
||||
AffinityGroup createAffinityGroupInternal(String account, Long domainId, String affinityGroupName, String affinityGroupType, String description);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +1,69 @@
|
|||
// 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.affinity;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public class AffinityProcessorBase extends AdapterBase implements AffinityGroupProcessor {
|
||||
|
||||
protected String _type;
|
||||
|
||||
@Override
|
||||
public void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
_type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination) throws AffinityConflictException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdminControlledGroup() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeSharedDomainWide() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDeleteGroup(AffinityGroup group) {
|
||||
// TODO Auto-generated method stub
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean subDomainAccess() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 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.affinity;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public class AffinityProcessorBase extends AdapterBase implements AffinityGroupProcessor {
|
||||
|
||||
protected String _type;
|
||||
|
||||
@Override
|
||||
public void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
_type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination) throws AffinityConflictException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdminControlledGroup() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeSharedDomainWide() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDeleteGroup(AffinityGroup group) {
|
||||
// TODO Auto-generated method stub
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean subDomainAccess() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +1,69 @@
|
|||
// 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.api.command.admin.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.response.DeploymentPlannersResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@APICommand(name = "listDeploymentPlanners", description = "Lists all DeploymentPlanners available.", responseObject = DeploymentPlannersResponse.class)
|
||||
public class ListDeploymentPlannersCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListDeploymentPlannersCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listdeploymentplannersresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
List<String> planners = _mgr.listDeploymentPlanners();
|
||||
ListResponse<DeploymentPlannersResponse> response = new ListResponse<DeploymentPlannersResponse>();
|
||||
List<DeploymentPlannersResponse> plannerResponses = new ArrayList<DeploymentPlannersResponse>();
|
||||
|
||||
for (String planner : planners) {
|
||||
DeploymentPlannersResponse plannerResponse = new DeploymentPlannersResponse();
|
||||
plannerResponse.setName(planner);
|
||||
plannerResponse.setObjectName("deploymentPlanner");
|
||||
plannerResponses.add(plannerResponse);
|
||||
}
|
||||
|
||||
response.setResponses(plannerResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
|
||||
}
|
||||
}
|
||||
// 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.api.command.admin.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.response.DeploymentPlannersResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@APICommand(name = "listDeploymentPlanners", description = "Lists all DeploymentPlanners available.", responseObject = DeploymentPlannersResponse.class)
|
||||
public class ListDeploymentPlannersCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListDeploymentPlannersCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listdeploymentplannersresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
List<String> planners = _mgr.listDeploymentPlanners();
|
||||
ListResponse<DeploymentPlannersResponse> response = new ListResponse<DeploymentPlannersResponse>();
|
||||
List<DeploymentPlannersResponse> plannerResponses = new ArrayList<DeploymentPlannersResponse>();
|
||||
|
||||
for (String planner : planners) {
|
||||
DeploymentPlannersResponse plannerResponse = new DeploymentPlannersResponse();
|
||||
plannerResponse.setName(planner);
|
||||
plannerResponse.setObjectName("deploymentPlanner");
|
||||
plannerResponses.add(plannerResponse);
|
||||
}
|
||||
|
||||
response.setResponses(plannerResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,63 +1,63 @@
|
|||
// 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.bridge.service.core.ec2;
|
||||
|
||||
public class EC2ModifyInstanceAttribute {
|
||||
private String instanceId;
|
||||
private String instanceType;
|
||||
private String userData;
|
||||
|
||||
/**
|
||||
* @return instanceId
|
||||
*/
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instanceId to set
|
||||
*/
|
||||
public void setInstanceId(String instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return instanceType
|
||||
*/
|
||||
public String getInstanceType() {
|
||||
return instanceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instanceType to set
|
||||
*/
|
||||
public void setInstanceType(String instanceType) {
|
||||
this.instanceType = instanceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return userData
|
||||
*/
|
||||
public String getUserData() {
|
||||
return userData;
|
||||
}
|
||||
|
||||
public void setUserData(String userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
}
|
||||
// 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.bridge.service.core.ec2;
|
||||
|
||||
public class EC2ModifyInstanceAttribute {
|
||||
private String instanceId;
|
||||
private String instanceType;
|
||||
private String userData;
|
||||
|
||||
/**
|
||||
* @return instanceId
|
||||
*/
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instanceId to set
|
||||
*/
|
||||
public void setInstanceId(String instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return instanceType
|
||||
*/
|
||||
public String getInstanceType() {
|
||||
return instanceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instanceType to set
|
||||
*/
|
||||
public void setInstanceType(String instanceType) {
|
||||
this.instanceType = instanceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return userData
|
||||
*/
|
||||
public String getUserData() {
|
||||
return userData;
|
||||
}
|
||||
|
||||
public void setUserData(String userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,34 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api;
|
||||
|
||||
public class UnregisterVMCommand extends Command {
|
||||
String vmName;
|
||||
|
||||
public UnregisterVMCommand(String vmName) {
|
||||
this.vmName = vmName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
}
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.api;
|
||||
|
||||
public class UnregisterVMCommand extends Command {
|
||||
String vmName;
|
||||
|
||||
public UnregisterVMCommand(String vmName) {
|
||||
this.vmName = vmName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,49 +1,49 @@
|
|||
// 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.deploy;
|
||||
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public interface DeploymentPlanningManager extends Manager {
|
||||
|
||||
/**
|
||||
* Manages vm deployment stages: First Process Affinity/Anti-affinity - Call
|
||||
* the chain of AffinityGroupProcessor adapters to set deploymentplan scope
|
||||
* and exclude list Secondly, Call DeploymentPlanner - to use heuristics to
|
||||
* find the best spot to place the vm/volume. Planner will drill down to the
|
||||
* write set of clusters to look for placement based on various heuristics.
|
||||
* Lastly, Call Allocators - Given a cluster, allocators matches the
|
||||
* requirements to capabilities of the physical resource (host, storage
|
||||
* pool).
|
||||
*
|
||||
* @throws AffinityConflictException
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
DeployDestination planDeployment(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException,
|
||||
AffinityConflictException;
|
||||
|
||||
String finalizeReservation(DeployDestination plannedDestination, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids)
|
||||
throws InsufficientServerCapacityException, AffinityConflictException;
|
||||
|
||||
void cleanupVMReservations();
|
||||
}
|
||||
// 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.deploy;
|
||||
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public interface DeploymentPlanningManager extends Manager {
|
||||
|
||||
/**
|
||||
* Manages vm deployment stages: First Process Affinity/Anti-affinity - Call
|
||||
* the chain of AffinityGroupProcessor adapters to set deploymentplan scope
|
||||
* and exclude list Secondly, Call DeploymentPlanner - to use heuristics to
|
||||
* find the best spot to place the vm/volume. Planner will drill down to the
|
||||
* write set of clusters to look for placement based on various heuristics.
|
||||
* Lastly, Call Allocators - Given a cluster, allocators matches the
|
||||
* requirements to capabilities of the physical resource (host, storage
|
||||
* pool).
|
||||
*
|
||||
* @throws AffinityConflictException
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
DeployDestination planDeployment(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException,
|
||||
AffinityConflictException;
|
||||
|
||||
String finalizeReservation(DeployDestination plannedDestination, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids)
|
||||
throws InsufficientServerCapacityException, AffinityConflictException;
|
||||
|
||||
void cleanupVMReservations();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +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 org.apache.cloudstack.framework.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ConfigDepot is a repository of configurations.
|
||||
*
|
||||
*/
|
||||
public interface ConfigDepot {
|
||||
|
||||
ConfigKey<?> get(String paramName);
|
||||
|
||||
List<ConfigKey<?>> getConfigListByScope(String scope);
|
||||
}
|
||||
// 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.framework.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ConfigDepot is a repository of configurations.
|
||||
*
|
||||
*/
|
||||
public interface ConfigDepot {
|
||||
|
||||
ConfigKey<?> get(String paramName);
|
||||
|
||||
List<ConfigKey<?>> getConfigListByScope(String scope);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,187 +1,187 @@
|
|||
// 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.framework.config;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
* ConfigKey supplants the original Config.java. It is just a class
|
||||
* declaration where others can declare their config variables.
|
||||
*
|
||||
*/
|
||||
public class ConfigKey<T> {
|
||||
|
||||
public static enum Scope {
|
||||
Global, Zone, Cluster, StoragePool, Account, ManagementServer
|
||||
}
|
||||
|
||||
private final String _category;
|
||||
|
||||
public String category() {
|
||||
return _category;
|
||||
}
|
||||
|
||||
public Class<T> type() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public final String key() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public String defaultValue() {
|
||||
return _defaultValue;
|
||||
}
|
||||
|
||||
public String description() {
|
||||
return _description;
|
||||
}
|
||||
|
||||
public Scope scope() {
|
||||
return _scope;
|
||||
}
|
||||
|
||||
public boolean isDynamic() {
|
||||
return _isDynamic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
private final Class<T> _type;
|
||||
private final String _name;
|
||||
private final String _defaultValue;
|
||||
private final String _description;
|
||||
private final Scope _scope; // Parameter can be at different levels (Zone/cluster/pool/account), by default every parameter is at global
|
||||
private final boolean _isDynamic;
|
||||
private final T _multiplier;
|
||||
T _value = null;
|
||||
|
||||
static ConfigDepotImpl s_depot = null;
|
||||
|
||||
static public void init(ConfigDepotImpl depot) {
|
||||
s_depot = depot;
|
||||
}
|
||||
|
||||
public ConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean isDynamic, Scope scope) {
|
||||
this(type, name, category, defaultValue, description, isDynamic, scope, null);
|
||||
}
|
||||
|
||||
public ConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean isDynamic) {
|
||||
this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null);
|
||||
}
|
||||
|
||||
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier) {
|
||||
_category = category;
|
||||
_type = type;
|
||||
_name = name;
|
||||
_defaultValue = defaultValue;
|
||||
_description = description;
|
||||
_scope = scope;
|
||||
_isDynamic = isDynamic;
|
||||
_multiplier = multiplier;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic) {
|
||||
this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null);
|
||||
}
|
||||
|
||||
public T multiplier() {
|
||||
return _multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return _name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ConfigKey) {
|
||||
ConfigKey<?> that = (ConfigKey<?>)obj;
|
||||
return this._name.equals(that._name);
|
||||
} else if (obj instanceof String) {
|
||||
String key = (String)obj;
|
||||
return key.equals(_name);
|
||||
}
|
||||
|
||||
throw new CloudRuntimeException("Comparing ConfigKey to " + obj.toString());
|
||||
}
|
||||
|
||||
public T value() {
|
||||
if (_value == null || isDynamic()) {
|
||||
ConfigurationVO vo = s_depot != null ? s_depot.global().findById(key()) : null;
|
||||
_value = valueOf(vo != null ? vo.getValue() : defaultValue());
|
||||
}
|
||||
|
||||
return _value;
|
||||
}
|
||||
|
||||
public T valueIn(Long id) {
|
||||
if (id == null) {
|
||||
return value();
|
||||
}
|
||||
|
||||
String value = s_depot != null ? s_depot.scoped(this).getConfigValue(id, this) : null;
|
||||
if (value == null) {
|
||||
return value();
|
||||
} else {
|
||||
return valueOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T valueOf(String value) {
|
||||
Number multiplier = 1;
|
||||
if (multiplier() != null) {
|
||||
multiplier = (Number)multiplier();
|
||||
}
|
||||
Class<T> type = type();
|
||||
if (type.isAssignableFrom(Boolean.class)) {
|
||||
return (T)Boolean.valueOf(value);
|
||||
} else if (type.isAssignableFrom(Integer.class)) {
|
||||
return (T)new Integer(Integer.parseInt(value) * multiplier.intValue());
|
||||
} else if (type.isAssignableFrom(Long.class)) {
|
||||
return (T)new Long(Long.parseLong(value) * multiplier.longValue());
|
||||
} else if (type.isAssignableFrom(Short.class)) {
|
||||
return (T)new Short(Short.parseShort(value));
|
||||
} else if (type.isAssignableFrom(String.class)) {
|
||||
return (T)value;
|
||||
} else if (type.isAssignableFrom(Float.class)) {
|
||||
return (T)new Float(Float.parseFloat(value) * multiplier.floatValue());
|
||||
} else if (type.isAssignableFrom(Double.class)) {
|
||||
return (T)new Double(Double.parseDouble(value) * multiplier.doubleValue());
|
||||
} else if (type.isAssignableFrom(String.class)) {
|
||||
return (T)value;
|
||||
} else if (type.isAssignableFrom(Date.class)) {
|
||||
return (T)Date.valueOf(value);
|
||||
} else if (type.isAssignableFrom(Character.class)) {
|
||||
return (T)new Character(value.charAt(0));
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unsupported data type for config values: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 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.framework.config;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
* ConfigKey supplants the original Config.java. It is just a class
|
||||
* declaration where others can declare their config variables.
|
||||
*
|
||||
*/
|
||||
public class ConfigKey<T> {
|
||||
|
||||
public static enum Scope {
|
||||
Global, Zone, Cluster, StoragePool, Account, ManagementServer
|
||||
}
|
||||
|
||||
private final String _category;
|
||||
|
||||
public String category() {
|
||||
return _category;
|
||||
}
|
||||
|
||||
public Class<T> type() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public final String key() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public String defaultValue() {
|
||||
return _defaultValue;
|
||||
}
|
||||
|
||||
public String description() {
|
||||
return _description;
|
||||
}
|
||||
|
||||
public Scope scope() {
|
||||
return _scope;
|
||||
}
|
||||
|
||||
public boolean isDynamic() {
|
||||
return _isDynamic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
private final Class<T> _type;
|
||||
private final String _name;
|
||||
private final String _defaultValue;
|
||||
private final String _description;
|
||||
private final Scope _scope; // Parameter can be at different levels (Zone/cluster/pool/account), by default every parameter is at global
|
||||
private final boolean _isDynamic;
|
||||
private final T _multiplier;
|
||||
T _value = null;
|
||||
|
||||
static ConfigDepotImpl s_depot = null;
|
||||
|
||||
static public void init(ConfigDepotImpl depot) {
|
||||
s_depot = depot;
|
||||
}
|
||||
|
||||
public ConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean isDynamic, Scope scope) {
|
||||
this(type, name, category, defaultValue, description, isDynamic, scope, null);
|
||||
}
|
||||
|
||||
public ConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean isDynamic) {
|
||||
this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null);
|
||||
}
|
||||
|
||||
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier) {
|
||||
_category = category;
|
||||
_type = type;
|
||||
_name = name;
|
||||
_defaultValue = defaultValue;
|
||||
_description = description;
|
||||
_scope = scope;
|
||||
_isDynamic = isDynamic;
|
||||
_multiplier = multiplier;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic) {
|
||||
this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null);
|
||||
}
|
||||
|
||||
public T multiplier() {
|
||||
return _multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return _name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ConfigKey) {
|
||||
ConfigKey<?> that = (ConfigKey<?>)obj;
|
||||
return this._name.equals(that._name);
|
||||
} else if (obj instanceof String) {
|
||||
String key = (String)obj;
|
||||
return key.equals(_name);
|
||||
}
|
||||
|
||||
throw new CloudRuntimeException("Comparing ConfigKey to " + obj.toString());
|
||||
}
|
||||
|
||||
public T value() {
|
||||
if (_value == null || isDynamic()) {
|
||||
ConfigurationVO vo = s_depot != null ? s_depot.global().findById(key()) : null;
|
||||
_value = valueOf(vo != null ? vo.getValue() : defaultValue());
|
||||
}
|
||||
|
||||
return _value;
|
||||
}
|
||||
|
||||
public T valueIn(Long id) {
|
||||
if (id == null) {
|
||||
return value();
|
||||
}
|
||||
|
||||
String value = s_depot != null ? s_depot.scoped(this).getConfigValue(id, this) : null;
|
||||
if (value == null) {
|
||||
return value();
|
||||
} else {
|
||||
return valueOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T valueOf(String value) {
|
||||
Number multiplier = 1;
|
||||
if (multiplier() != null) {
|
||||
multiplier = (Number)multiplier();
|
||||
}
|
||||
Class<T> type = type();
|
||||
if (type.isAssignableFrom(Boolean.class)) {
|
||||
return (T)Boolean.valueOf(value);
|
||||
} else if (type.isAssignableFrom(Integer.class)) {
|
||||
return (T)new Integer(Integer.parseInt(value) * multiplier.intValue());
|
||||
} else if (type.isAssignableFrom(Long.class)) {
|
||||
return (T)new Long(Long.parseLong(value) * multiplier.longValue());
|
||||
} else if (type.isAssignableFrom(Short.class)) {
|
||||
return (T)new Short(Short.parseShort(value));
|
||||
} else if (type.isAssignableFrom(String.class)) {
|
||||
return (T)value;
|
||||
} else if (type.isAssignableFrom(Float.class)) {
|
||||
return (T)new Float(Float.parseFloat(value) * multiplier.floatValue());
|
||||
} else if (type.isAssignableFrom(Double.class)) {
|
||||
return (T)new Double(Double.parseDouble(value) * multiplier.doubleValue());
|
||||
} else if (type.isAssignableFrom(String.class)) {
|
||||
return (T)value;
|
||||
} else if (type.isAssignableFrom(Date.class)) {
|
||||
return (T)Date.valueOf(value);
|
||||
} else if (type.isAssignableFrom(Character.class)) {
|
||||
return (T)new Character(value.charAt(0));
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unsupported data type for config values: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,149 +1,149 @@
|
|||
// 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.affinity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@Local(value = AffinityGroupProcessor.class)
|
||||
public class HostAntiAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class);
|
||||
@Inject
|
||||
protected UserVmDao _vmDao;
|
||||
@Inject
|
||||
protected VMInstanceDao _vmInstanceDao;
|
||||
@Inject
|
||||
protected AffinityGroupDao _affinityGroupDao;
|
||||
@Inject
|
||||
protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
|
||||
private int _vmCapacityReleaseInterval;
|
||||
@Inject
|
||||
protected ConfigurationDao _configDao;
|
||||
|
||||
@Inject
|
||||
protected VMReservationDao _reservationDao;
|
||||
|
||||
@Override
|
||||
public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException {
|
||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
|
||||
|
||||
for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
|
||||
if (vmGroupMapping != null) {
|
||||
AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId());
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId());
|
||||
}
|
||||
|
||||
List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId());
|
||||
groupVMIds.remove(vm.getId());
|
||||
|
||||
for (Long groupVMId : groupVMIds) {
|
||||
VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
|
||||
if (groupVM != null && !groupVM.isRemoved()) {
|
||||
if (groupVM.getHostId() != null) {
|
||||
avoid.addHost(groupVM.getHostId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host");
|
||||
}
|
||||
} else if (VirtualMachine.State.Stopped.equals(groupVM.getState()) && groupVM.getLastHostId() != null) {
|
||||
long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - groupVM.getUpdateTime().getTime()) / 1000;
|
||||
if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) {
|
||||
avoid.addHost(groupVM.getLastHostId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM " + groupVM.getId() +
|
||||
" is present on the host, in Stopped state but has reserved capacity");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
_vmCapacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedDestination) throws AffinityConflictException {
|
||||
|
||||
if (plannedDestination.getHost() == null) {
|
||||
return true;
|
||||
}
|
||||
long plannedHostId = plannedDestination.getHost().getId();
|
||||
|
||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||
|
||||
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
|
||||
|
||||
for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
|
||||
// if more than 1 VM's are present in the group then check for
|
||||
// conflict due to parallel deployment
|
||||
List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(vmGroupMapping.getAffinityGroupId());
|
||||
groupVMIds.remove(vm.getId());
|
||||
|
||||
for (Long groupVMId : groupVMIds) {
|
||||
VMReservationVO vmReservation = _reservationDao.findByVmId(groupVMId);
|
||||
if (vmReservation != null && vmReservation.getHostId() != null && vmReservation.getHostId().equals(plannedHostId)) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + " reserved on the same host " +
|
||||
plannedHostId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
// 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.affinity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@Local(value = AffinityGroupProcessor.class)
|
||||
public class HostAntiAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class);
|
||||
@Inject
|
||||
protected UserVmDao _vmDao;
|
||||
@Inject
|
||||
protected VMInstanceDao _vmInstanceDao;
|
||||
@Inject
|
||||
protected AffinityGroupDao _affinityGroupDao;
|
||||
@Inject
|
||||
protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
|
||||
private int _vmCapacityReleaseInterval;
|
||||
@Inject
|
||||
protected ConfigurationDao _configDao;
|
||||
|
||||
@Inject
|
||||
protected VMReservationDao _reservationDao;
|
||||
|
||||
@Override
|
||||
public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException {
|
||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
|
||||
|
||||
for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
|
||||
if (vmGroupMapping != null) {
|
||||
AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId());
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId());
|
||||
}
|
||||
|
||||
List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId());
|
||||
groupVMIds.remove(vm.getId());
|
||||
|
||||
for (Long groupVMId : groupVMIds) {
|
||||
VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
|
||||
if (groupVM != null && !groupVM.isRemoved()) {
|
||||
if (groupVM.getHostId() != null) {
|
||||
avoid.addHost(groupVM.getHostId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host");
|
||||
}
|
||||
} else if (VirtualMachine.State.Stopped.equals(groupVM.getState()) && groupVM.getLastHostId() != null) {
|
||||
long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - groupVM.getUpdateTime().getTime()) / 1000;
|
||||
if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) {
|
||||
avoid.addHost(groupVM.getLastHostId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM " + groupVM.getId() +
|
||||
" is present on the host, in Stopped state but has reserved capacity");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
_vmCapacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedDestination) throws AffinityConflictException {
|
||||
|
||||
if (plannedDestination.getHost() == null) {
|
||||
return true;
|
||||
}
|
||||
long plannedHostId = plannedDestination.getHost().getId();
|
||||
|
||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||
|
||||
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
|
||||
|
||||
for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
|
||||
// if more than 1 VM's are present in the group then check for
|
||||
// conflict due to parallel deployment
|
||||
List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(vmGroupMapping.getAffinityGroupId());
|
||||
groupVMIds.remove(vm.getId());
|
||||
|
||||
for (Long groupVMId : groupVMIds) {
|
||||
VMReservationVO vmReservation = _reservationDao.findByVmId(groupVMId);
|
||||
if (vmReservation != null && vmReservation.getHostId() != null && vmReservation.getHostId().equals(plannedHostId)) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + " reserved on the same host " +
|
||||
plannedHostId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
2
pom.xml
2
pom.xml
|
|
@ -445,7 +445,6 @@
|
|||
<outputDirectory>${basedir}/${cs.target.dir}/classes</outputDirectory>
|
||||
<testOutputDirectory>${basedir}/${cs.target.dir}/test-classes</testOutputDirectory>
|
||||
<plugins>
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
|
|
@ -475,7 +474,6 @@
|
|||
<excludes>**\/target\/,**\/bin\/,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
-->
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,32 +1,32 @@
|
|||
// 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.deploy.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.deploy.PlannerHostReservationVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface PlannerHostReservationDao extends GenericDao<PlannerHostReservationVO, Long> {
|
||||
|
||||
PlannerHostReservationVO findByHostId(long hostId);
|
||||
|
||||
List<PlannerHostReservationVO> listAllReservedHosts();
|
||||
|
||||
List<PlannerHostReservationVO> listAllDedicatedHosts();
|
||||
|
||||
}
|
||||
// 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.deploy.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.deploy.PlannerHostReservationVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface PlannerHostReservationDao extends GenericDao<PlannerHostReservationVO, Long> {
|
||||
|
||||
PlannerHostReservationVO findByHostId(long hostId);
|
||||
|
||||
List<PlannerHostReservationVO> listAllReservedHosts();
|
||||
|
||||
List<PlannerHostReservationVO> listAllDedicatedHosts();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,75 +1,75 @@
|
|||
// 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.deploy.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
|
||||
import com.cloud.deploy.PlannerHostReservationVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
@Local(value = {PlannerHostReservationDao.class})
|
||||
public class PlannerHostReservationDaoImpl extends GenericDaoBase<PlannerHostReservationVO, Long> implements PlannerHostReservationDao {
|
||||
|
||||
private SearchBuilder<PlannerHostReservationVO> _hostIdSearch;
|
||||
private SearchBuilder<PlannerHostReservationVO> _reservedHostSearch;
|
||||
private SearchBuilder<PlannerHostReservationVO> _dedicatedHostSearch;;
|
||||
|
||||
public PlannerHostReservationDaoImpl() {
|
||||
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
_hostIdSearch = createSearchBuilder();
|
||||
_hostIdSearch.and("hostId", _hostIdSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
_hostIdSearch.done();
|
||||
|
||||
_reservedHostSearch = createSearchBuilder();
|
||||
_reservedHostSearch.and("usage", _reservedHostSearch.entity().getResourceUsage(), SearchCriteria.Op.NNULL);
|
||||
_reservedHostSearch.done();
|
||||
|
||||
_dedicatedHostSearch = createSearchBuilder();
|
||||
_dedicatedHostSearch.and("usage", _dedicatedHostSearch.entity().getResourceUsage(), SearchCriteria.Op.EQ);
|
||||
_dedicatedHostSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlannerHostReservationVO findByHostId(long hostId) {
|
||||
SearchCriteria<PlannerHostReservationVO> sc = _hostIdSearch.create();
|
||||
sc.setParameters("hostId", hostId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlannerHostReservationVO> listAllReservedHosts() {
|
||||
SearchCriteria<PlannerHostReservationVO> sc = _reservedHostSearch.create();
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlannerHostReservationVO> listAllDedicatedHosts() {
|
||||
SearchCriteria<PlannerHostReservationVO> sc = _dedicatedHostSearch.create();
|
||||
sc.setParameters("usage", PlannerResourceUsage.Dedicated);
|
||||
return listBy(sc);
|
||||
}
|
||||
// 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.deploy.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
|
||||
import com.cloud.deploy.PlannerHostReservationVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
@Local(value = {PlannerHostReservationDao.class})
|
||||
public class PlannerHostReservationDaoImpl extends GenericDaoBase<PlannerHostReservationVO, Long> implements PlannerHostReservationDao {
|
||||
|
||||
private SearchBuilder<PlannerHostReservationVO> _hostIdSearch;
|
||||
private SearchBuilder<PlannerHostReservationVO> _reservedHostSearch;
|
||||
private SearchBuilder<PlannerHostReservationVO> _dedicatedHostSearch;;
|
||||
|
||||
public PlannerHostReservationDaoImpl() {
|
||||
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
_hostIdSearch = createSearchBuilder();
|
||||
_hostIdSearch.and("hostId", _hostIdSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
_hostIdSearch.done();
|
||||
|
||||
_reservedHostSearch = createSearchBuilder();
|
||||
_reservedHostSearch.and("usage", _reservedHostSearch.entity().getResourceUsage(), SearchCriteria.Op.NNULL);
|
||||
_reservedHostSearch.done();
|
||||
|
||||
_dedicatedHostSearch = createSearchBuilder();
|
||||
_dedicatedHostSearch.and("usage", _dedicatedHostSearch.entity().getResourceUsage(), SearchCriteria.Op.EQ);
|
||||
_dedicatedHostSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlannerHostReservationVO findByHostId(long hostId) {
|
||||
SearchCriteria<PlannerHostReservationVO> sc = _hostIdSearch.create();
|
||||
sc.setParameters("hostId", hostId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlannerHostReservationVO> listAllReservedHosts() {
|
||||
SearchCriteria<PlannerHostReservationVO> sc = _reservedHostSearch.create();
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlannerHostReservationVO> listAllDedicatedHosts() {
|
||||
SearchCriteria<PlannerHostReservationVO> sc = _dedicatedHostSearch.create();
|
||||
sc.setParameters("usage", PlannerResourceUsage.Dedicated);
|
||||
return listBy(sc);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,383 +1,383 @@
|
|||
// 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.vm;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
import com.cloud.storage.dao.GuestOSCategoryDao;
|
||||
import com.cloud.storage.dao.GuestOSDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.capacity.CapacityManager;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.DedicatedResourceDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentClusterPlanner;
|
||||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
|
||||
import com.cloud.deploy.DeploymentPlanningManagerImpl;
|
||||
import com.cloud.deploy.FirstFitPlanner;
|
||||
import com.cloud.deploy.PlannerHostReservationVO;
|
||||
import com.cloud.deploy.dao.PlannerHostReservationDao;
|
||||
|
||||
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupService;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageBus;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
public class DeploymentPlanningManagerImplTest {
|
||||
|
||||
@Inject
|
||||
DeploymentPlanningManagerImpl _dpm;
|
||||
|
||||
@Inject
|
||||
PlannerHostReservationDao _plannerHostReserveDao;
|
||||
|
||||
@Inject
|
||||
VirtualMachineProfileImpl vmProfile;
|
||||
|
||||
@Inject
|
||||
AffinityGroupVMMapDao _affinityGroupVMMapDao;
|
||||
|
||||
@Inject
|
||||
ExcludeList avoids;
|
||||
|
||||
@Inject
|
||||
DataCenterVO dc;
|
||||
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
|
||||
@Inject
|
||||
FirstFitPlanner _planner;
|
||||
|
||||
@Inject
|
||||
ClusterDao _clusterDao;
|
||||
|
||||
@Inject
|
||||
DedicatedResourceDao _dedicatedDao;
|
||||
|
||||
private static long domainId = 5L;
|
||||
|
||||
private static long dataCenterId = 1L;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws ConfigurationException {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void testSetUp() {
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
|
||||
PlannerHostReservationVO reservationVO = new PlannerHostReservationVO(200L, 1L, 2L, 3L, PlannerResourceUsage.Shared);
|
||||
Mockito.when(_plannerHostReserveDao.persist(Mockito.any(PlannerHostReservationVO.class))).thenReturn(reservationVO);
|
||||
Mockito.when(_plannerHostReserveDao.findById(Mockito.anyLong())).thenReturn(reservationVO);
|
||||
Mockito.when(_affinityGroupVMMapDao.countAffinityGroupsForVm(Mockito.anyLong())).thenReturn(0L);
|
||||
|
||||
VMInstanceVO vm = new VMInstanceVO();
|
||||
Mockito.when(vmProfile.getVirtualMachine()).thenReturn(vm);
|
||||
|
||||
Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
|
||||
Mockito.when(dc.getId()).thenReturn(dataCenterId);
|
||||
|
||||
ClusterVO clusterVO = new ClusterVO();
|
||||
clusterVO.setHypervisorType(HypervisorType.XenServer.toString());
|
||||
Mockito.when(_clusterDao.findById(Mockito.anyLong())).thenReturn(clusterVO);
|
||||
|
||||
Mockito.when(_planner.getName()).thenReturn("FirstFitPlanner");
|
||||
List<DeploymentPlanner> planners = new ArrayList<DeploymentPlanner>();
|
||||
planners.add(_planner);
|
||||
_dpm.setPlanners(planners);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataCenterAvoidTest() throws InsufficientServerCapacityException, AffinityConflictException {
|
||||
ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm", false, false, null, false,
|
||||
VirtualMachine.Type.User, domainId, null, "FirstFitPlanner");
|
||||
Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
|
||||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
|
||||
|
||||
Mockito.when(avoids.shouldAvoid((DataCenterVO)Mockito.anyObject())).thenReturn(true);
|
||||
DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
|
||||
assertNull("DataCenter is in avoid set, destination should be null! ", dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plannerCannotHandleTest() throws InsufficientServerCapacityException, AffinityConflictException {
|
||||
ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm", false, false, null, false,
|
||||
VirtualMachine.Type.User, domainId, null, "UserDispersingPlanner");
|
||||
Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
|
||||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
|
||||
Mockito.when(avoids.shouldAvoid((DataCenterVO)Mockito.anyObject())).thenReturn(false);
|
||||
|
||||
Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(false);
|
||||
DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
|
||||
assertNull("Planner cannot handle, destination should be null! ", dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyClusterListTest() throws InsufficientServerCapacityException, AffinityConflictException {
|
||||
ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm", false, false, null, false,
|
||||
VirtualMachine.Type.User, domainId, null, "FirstFitPlanner");
|
||||
Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
|
||||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
|
||||
Mockito.when(avoids.shouldAvoid((DataCenterVO)Mockito.anyObject())).thenReturn(false);
|
||||
Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(true);
|
||||
|
||||
Mockito.when(((DeploymentClusterPlanner)_planner).orderClusters(vmProfile, plan, avoids)).thenReturn(null);
|
||||
DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
|
||||
assertNull("Planner cannot handle, destination should be null! ", dest);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = {DeploymentPlanningManagerImpl.class},
|
||||
includeFilters = {@Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM)},
|
||||
useDefaultFilters = false)
|
||||
public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
|
||||
|
||||
@Bean
|
||||
public FirstFitPlanner firstFitPlanner() {
|
||||
return Mockito.mock(FirstFitPlanner.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DeploymentPlanner deploymentPlanner() {
|
||||
return Mockito.mock(DeploymentPlanner.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataCenterVO dataCenter() {
|
||||
return Mockito.mock(DataCenterVO.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ExcludeList excludeList() {
|
||||
return Mockito.mock(ExcludeList.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VirtualMachineProfileImpl virtualMachineProfileImpl() {
|
||||
return Mockito.mock(VirtualMachineProfileImpl.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClusterDetailsDao clusterDetailsDao() {
|
||||
return Mockito.mock(ClusterDetailsDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataStoreManager cataStoreManager() {
|
||||
return Mockito.mock(DataStoreManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StorageManager storageManager() {
|
||||
return Mockito.mock(StorageManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HostDao hostDao() {
|
||||
return Mockito.mock(HostDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HostPodDao hostPodDao() {
|
||||
return Mockito.mock(HostPodDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClusterDao clusterDao() {
|
||||
return Mockito.mock(ClusterDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DedicatedResourceDao dedicatedResourceDao() {
|
||||
return Mockito.mock(DedicatedResourceDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GuestOSDao guestOSDao() {
|
||||
return Mockito.mock(GuestOSDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GuestOSCategoryDao guestOSCategoryDao() {
|
||||
return Mockito.mock(GuestOSCategoryDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CapacityManager capacityManager() {
|
||||
return Mockito.mock(CapacityManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StoragePoolHostDao storagePoolHostDao() {
|
||||
return Mockito.mock(StoragePoolHostDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VolumeDao volumeDao() {
|
||||
return Mockito.mock(VolumeDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConfigurationDao configurationDao() {
|
||||
return Mockito.mock(ConfigurationDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DiskOfferingDao diskOfferingDao() {
|
||||
return Mockito.mock(DiskOfferingDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PrimaryDataStoreDao primaryDataStoreDao() {
|
||||
return Mockito.mock(PrimaryDataStoreDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CapacityDao capacityDao() {
|
||||
return Mockito.mock(CapacityDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlannerHostReservationDao plannerHostReservationDao() {
|
||||
return Mockito.mock(PlannerHostReservationDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupProcessor affinityGroupProcessor() {
|
||||
return Mockito.mock(AffinityGroupProcessor.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupDao affinityGroupDao() {
|
||||
return Mockito.mock(AffinityGroupDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupVMMapDao affinityGroupVMMapDao() {
|
||||
return Mockito.mock(AffinityGroupVMMapDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountManager accountManager() {
|
||||
return Mockito.mock(AccountManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AgentManager agentManager() {
|
||||
return Mockito.mock(AgentManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageBus messageBus() {
|
||||
return Mockito.mock(MessageBus.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserVmDao userVMDao() {
|
||||
return Mockito.mock(UserVmDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VMInstanceDao vmInstanceDao() {
|
||||
return Mockito.mock(VMInstanceDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataCenterDao dataCenterDao() {
|
||||
return Mockito.mock(DataCenterDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VMReservationDao reservationDao() {
|
||||
return Mockito.mock(VMReservationDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupService affinityGroupService() {
|
||||
return Mockito.mock(AffinityGroupService.class);
|
||||
}
|
||||
|
||||
public static class Library implements TypeFilter {
|
||||
|
||||
@Override
|
||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||
ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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.vm;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
import com.cloud.storage.dao.GuestOSCategoryDao;
|
||||
import com.cloud.storage.dao.GuestOSDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.capacity.CapacityManager;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.DedicatedResourceDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentClusterPlanner;
|
||||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
|
||||
import com.cloud.deploy.DeploymentPlanningManagerImpl;
|
||||
import com.cloud.deploy.FirstFitPlanner;
|
||||
import com.cloud.deploy.PlannerHostReservationVO;
|
||||
import com.cloud.deploy.dao.PlannerHostReservationDao;
|
||||
|
||||
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupService;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageBus;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
public class DeploymentPlanningManagerImplTest {
|
||||
|
||||
@Inject
|
||||
DeploymentPlanningManagerImpl _dpm;
|
||||
|
||||
@Inject
|
||||
PlannerHostReservationDao _plannerHostReserveDao;
|
||||
|
||||
@Inject
|
||||
VirtualMachineProfileImpl vmProfile;
|
||||
|
||||
@Inject
|
||||
AffinityGroupVMMapDao _affinityGroupVMMapDao;
|
||||
|
||||
@Inject
|
||||
ExcludeList avoids;
|
||||
|
||||
@Inject
|
||||
DataCenterVO dc;
|
||||
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
|
||||
@Inject
|
||||
FirstFitPlanner _planner;
|
||||
|
||||
@Inject
|
||||
ClusterDao _clusterDao;
|
||||
|
||||
@Inject
|
||||
DedicatedResourceDao _dedicatedDao;
|
||||
|
||||
private static long domainId = 5L;
|
||||
|
||||
private static long dataCenterId = 1L;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws ConfigurationException {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void testSetUp() {
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
|
||||
PlannerHostReservationVO reservationVO = new PlannerHostReservationVO(200L, 1L, 2L, 3L, PlannerResourceUsage.Shared);
|
||||
Mockito.when(_plannerHostReserveDao.persist(Mockito.any(PlannerHostReservationVO.class))).thenReturn(reservationVO);
|
||||
Mockito.when(_plannerHostReserveDao.findById(Mockito.anyLong())).thenReturn(reservationVO);
|
||||
Mockito.when(_affinityGroupVMMapDao.countAffinityGroupsForVm(Mockito.anyLong())).thenReturn(0L);
|
||||
|
||||
VMInstanceVO vm = new VMInstanceVO();
|
||||
Mockito.when(vmProfile.getVirtualMachine()).thenReturn(vm);
|
||||
|
||||
Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
|
||||
Mockito.when(dc.getId()).thenReturn(dataCenterId);
|
||||
|
||||
ClusterVO clusterVO = new ClusterVO();
|
||||
clusterVO.setHypervisorType(HypervisorType.XenServer.toString());
|
||||
Mockito.when(_clusterDao.findById(Mockito.anyLong())).thenReturn(clusterVO);
|
||||
|
||||
Mockito.when(_planner.getName()).thenReturn("FirstFitPlanner");
|
||||
List<DeploymentPlanner> planners = new ArrayList<DeploymentPlanner>();
|
||||
planners.add(_planner);
|
||||
_dpm.setPlanners(planners);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataCenterAvoidTest() throws InsufficientServerCapacityException, AffinityConflictException {
|
||||
ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm", false, false, null, false,
|
||||
VirtualMachine.Type.User, domainId, null, "FirstFitPlanner");
|
||||
Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
|
||||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
|
||||
|
||||
Mockito.when(avoids.shouldAvoid((DataCenterVO)Mockito.anyObject())).thenReturn(true);
|
||||
DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
|
||||
assertNull("DataCenter is in avoid set, destination should be null! ", dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plannerCannotHandleTest() throws InsufficientServerCapacityException, AffinityConflictException {
|
||||
ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm", false, false, null, false,
|
||||
VirtualMachine.Type.User, domainId, null, "UserDispersingPlanner");
|
||||
Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
|
||||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
|
||||
Mockito.when(avoids.shouldAvoid((DataCenterVO)Mockito.anyObject())).thenReturn(false);
|
||||
|
||||
Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(false);
|
||||
DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
|
||||
assertNull("Planner cannot handle, destination should be null! ", dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyClusterListTest() throws InsufficientServerCapacityException, AffinityConflictException {
|
||||
ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm", false, false, null, false,
|
||||
VirtualMachine.Type.User, domainId, null, "FirstFitPlanner");
|
||||
Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
|
||||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
|
||||
Mockito.when(avoids.shouldAvoid((DataCenterVO)Mockito.anyObject())).thenReturn(false);
|
||||
Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(true);
|
||||
|
||||
Mockito.when(((DeploymentClusterPlanner)_planner).orderClusters(vmProfile, plan, avoids)).thenReturn(null);
|
||||
DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
|
||||
assertNull("Planner cannot handle, destination should be null! ", dest);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = {DeploymentPlanningManagerImpl.class},
|
||||
includeFilters = {@Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM)},
|
||||
useDefaultFilters = false)
|
||||
public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
|
||||
|
||||
@Bean
|
||||
public FirstFitPlanner firstFitPlanner() {
|
||||
return Mockito.mock(FirstFitPlanner.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DeploymentPlanner deploymentPlanner() {
|
||||
return Mockito.mock(DeploymentPlanner.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataCenterVO dataCenter() {
|
||||
return Mockito.mock(DataCenterVO.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ExcludeList excludeList() {
|
||||
return Mockito.mock(ExcludeList.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VirtualMachineProfileImpl virtualMachineProfileImpl() {
|
||||
return Mockito.mock(VirtualMachineProfileImpl.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClusterDetailsDao clusterDetailsDao() {
|
||||
return Mockito.mock(ClusterDetailsDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataStoreManager cataStoreManager() {
|
||||
return Mockito.mock(DataStoreManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StorageManager storageManager() {
|
||||
return Mockito.mock(StorageManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HostDao hostDao() {
|
||||
return Mockito.mock(HostDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HostPodDao hostPodDao() {
|
||||
return Mockito.mock(HostPodDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClusterDao clusterDao() {
|
||||
return Mockito.mock(ClusterDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DedicatedResourceDao dedicatedResourceDao() {
|
||||
return Mockito.mock(DedicatedResourceDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GuestOSDao guestOSDao() {
|
||||
return Mockito.mock(GuestOSDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GuestOSCategoryDao guestOSCategoryDao() {
|
||||
return Mockito.mock(GuestOSCategoryDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CapacityManager capacityManager() {
|
||||
return Mockito.mock(CapacityManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StoragePoolHostDao storagePoolHostDao() {
|
||||
return Mockito.mock(StoragePoolHostDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VolumeDao volumeDao() {
|
||||
return Mockito.mock(VolumeDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConfigurationDao configurationDao() {
|
||||
return Mockito.mock(ConfigurationDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DiskOfferingDao diskOfferingDao() {
|
||||
return Mockito.mock(DiskOfferingDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PrimaryDataStoreDao primaryDataStoreDao() {
|
||||
return Mockito.mock(PrimaryDataStoreDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CapacityDao capacityDao() {
|
||||
return Mockito.mock(CapacityDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlannerHostReservationDao plannerHostReservationDao() {
|
||||
return Mockito.mock(PlannerHostReservationDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupProcessor affinityGroupProcessor() {
|
||||
return Mockito.mock(AffinityGroupProcessor.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupDao affinityGroupDao() {
|
||||
return Mockito.mock(AffinityGroupDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupVMMapDao affinityGroupVMMapDao() {
|
||||
return Mockito.mock(AffinityGroupVMMapDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountManager accountManager() {
|
||||
return Mockito.mock(AccountManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AgentManager agentManager() {
|
||||
return Mockito.mock(AgentManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageBus messageBus() {
|
||||
return Mockito.mock(MessageBus.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserVmDao userVMDao() {
|
||||
return Mockito.mock(UserVmDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VMInstanceDao vmInstanceDao() {
|
||||
return Mockito.mock(VMInstanceDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataCenterDao dataCenterDao() {
|
||||
return Mockito.mock(DataCenterDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VMReservationDao reservationDao() {
|
||||
return Mockito.mock(VMReservationDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupService affinityGroupService() {
|
||||
return Mockito.mock(AffinityGroupService.class);
|
||||
}
|
||||
|
||||
public static class Library implements TypeFilter {
|
||||
|
||||
@Override
|
||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||
ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,293 +1,293 @@
|
|||
// 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.affinity;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||
|
||||
import com.cloud.dc.dao.DedicatedResourceDao;
|
||||
import com.cloud.event.ActionEventUtils;
|
||||
import com.cloud.dc.dao.DedicatedResourceDao;
|
||||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.ActionEventUtils;
|
||||
import com.cloud.event.EventVO;
|
||||
import com.cloud.event.dao.EventDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceInUseException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.DomainManager;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
public class AffinityApiUnitTest {
|
||||
|
||||
@Inject
|
||||
AffinityGroupServiceImpl _affinityService;
|
||||
|
||||
@Inject
|
||||
AccountManager _acctMgr;
|
||||
|
||||
@Inject
|
||||
AffinityGroupProcessor _processor;
|
||||
|
||||
@Inject
|
||||
AffinityGroupDao _groupDao;
|
||||
|
||||
@Inject
|
||||
UserVmDao _vmDao;
|
||||
|
||||
@Inject
|
||||
AffinityGroupVMMapDao _affinityGroupVMMapDao;
|
||||
|
||||
@Inject
|
||||
AffinityGroupDao _affinityGroupDao;
|
||||
|
||||
@Inject
|
||||
ActionEventUtils _eventUtils;
|
||||
|
||||
@Inject
|
||||
AccountDao _accountDao;
|
||||
|
||||
@Inject
|
||||
EventDao _eventDao;
|
||||
|
||||
@Inject
|
||||
DedicatedResourceDao _dedicatedDao;
|
||||
|
||||
private static long domainId = 5L;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws ConfigurationException {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
AccountVO acct = new AccountVO(200L);
|
||||
acct.setType(Account.ACCOUNT_TYPE_NORMAL);
|
||||
acct.setAccountName("user");
|
||||
acct.setDomainId(domainId);
|
||||
|
||||
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
|
||||
|
||||
CallContext.register(user, acct);
|
||||
|
||||
when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
|
||||
when(_processor.getType()).thenReturn("mock");
|
||||
when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
|
||||
|
||||
List<AffinityGroupProcessor> affinityProcessors = new ArrayList<AffinityGroupProcessor>();
|
||||
affinityProcessors.add(_processor);
|
||||
_affinityService.setAffinityGroupProcessors(affinityProcessors);
|
||||
|
||||
AffinityGroupVO group = new AffinityGroupVO("group1", "mock", "mock group", domainId, 200L, ControlledEntity.ACLType.Account);
|
||||
Mockito.when(_affinityGroupDao.persist(Mockito.any(AffinityGroupVO.class))).thenReturn(group);
|
||||
Mockito.when(_affinityGroupDao.findById(Mockito.anyLong())).thenReturn(group);
|
||||
Mockito.when(_affinityGroupDao.findByAccountAndName(Mockito.anyLong(), Mockito.anyString())).thenReturn(group);
|
||||
Mockito.when(_affinityGroupDao.lockRow(Mockito.anyLong(), anyBoolean())).thenReturn(group);
|
||||
Mockito.when(_affinityGroupDao.expunge(Mockito.anyLong())).thenReturn(true);
|
||||
Mockito.when(_eventDao.persist(Mockito.any(EventVO.class))).thenReturn(new EventVO());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
CallContext.unregister();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAffinityGroupTest() {
|
||||
when(_groupDao.isNameInUse(anyLong(), anyLong(), eq("group1"))).thenReturn(false);
|
||||
AffinityGroup group = _affinityService.createAffinityGroup("user", domainId, "group1", "mock", "affinity group one");
|
||||
assertNotNull("Affinity group 'group1' of type 'mock' failed to create ", group);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void invalidAffinityTypeTest() {
|
||||
AffinityGroup group = _affinityService.createAffinityGroup("user", domainId, "group1", "invalid", "affinity group one");
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void uniqueAffinityNameTest() {
|
||||
when(_groupDao.isNameInUse(anyLong(), anyLong(), eq("group1"))).thenReturn(true);
|
||||
AffinityGroup group2 = _affinityService.createAffinityGroup("user", domainId, "group1", "mock", "affinity group two");
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void deleteAffinityGroupInvalidIdTest() throws ResourceInUseException {
|
||||
when(_groupDao.findById(20L)).thenReturn(null);
|
||||
_affinityService.deleteAffinityGroup(20L, "user", domainId, "group1");
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void deleteAffinityGroupInvalidIdName() throws ResourceInUseException {
|
||||
when(_groupDao.findByAccountAndName(200L, "group1")).thenReturn(null);
|
||||
_affinityService.deleteAffinityGroup(null, "user", domainId, "group1");
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void deleteAffinityGroupNullIdName() throws ResourceInUseException {
|
||||
_affinityService.deleteAffinityGroup(null, "user", domainId, null);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void updateAffinityGroupVMRunning() throws ResourceInUseException {
|
||||
|
||||
UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false, domainId, 200L, 5L, "", "test", 1L);
|
||||
vm.setState(VirtualMachine.State.Running);
|
||||
when(_vmDao.findById(10L)).thenReturn(vm);
|
||||
|
||||
List<Long> affinityGroupIds = new ArrayList<Long>();
|
||||
affinityGroupIds.add(20L);
|
||||
|
||||
_affinityService.updateVMAffinityGroups(10L, affinityGroupIds);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = {AffinityGroupServiceImpl.class, ActionEventUtils.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class,
|
||||
type = FilterType.CUSTOM)}, useDefaultFilters = false)
|
||||
public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
|
||||
|
||||
@Bean
|
||||
public AccountDao accountDao() {
|
||||
return Mockito.mock(AccountDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountService accountService() {
|
||||
return Mockito.mock(AccountService.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupProcessor affinityGroupProcessor() {
|
||||
return Mockito.mock(AffinityGroupProcessor.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupDao affinityGroupDao() {
|
||||
return Mockito.mock(AffinityGroupDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupVMMapDao affinityGroupVMMapDao() {
|
||||
return Mockito.mock(AffinityGroupVMMapDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DedicatedResourceDao dedicatedResourceDao() {
|
||||
return Mockito.mock(DedicatedResourceDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountManager accountManager() {
|
||||
return Mockito.mock(AccountManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DomainManager domainManager() {
|
||||
return Mockito.mock(DomainManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EventDao eventDao() {
|
||||
return Mockito.mock(EventDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserVmDao userVMDao() {
|
||||
return Mockito.mock(UserVmDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserDao userDao() {
|
||||
return Mockito.mock(UserDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupDomainMapDao affinityGroupDomainMapDao() {
|
||||
return Mockito.mock(AffinityGroupDomainMapDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DomainDao domainDao() {
|
||||
return Mockito.mock(DomainDao.class);
|
||||
}
|
||||
|
||||
public static class Library implements TypeFilter {
|
||||
|
||||
@Override
|
||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||
ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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.affinity;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||
|
||||
import com.cloud.dc.dao.DedicatedResourceDao;
|
||||
import com.cloud.event.ActionEventUtils;
|
||||
import com.cloud.dc.dao.DedicatedResourceDao;
|
||||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.ActionEventUtils;
|
||||
import com.cloud.event.EventVO;
|
||||
import com.cloud.event.dao.EventDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceInUseException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.DomainManager;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
public class AffinityApiUnitTest {
|
||||
|
||||
@Inject
|
||||
AffinityGroupServiceImpl _affinityService;
|
||||
|
||||
@Inject
|
||||
AccountManager _acctMgr;
|
||||
|
||||
@Inject
|
||||
AffinityGroupProcessor _processor;
|
||||
|
||||
@Inject
|
||||
AffinityGroupDao _groupDao;
|
||||
|
||||
@Inject
|
||||
UserVmDao _vmDao;
|
||||
|
||||
@Inject
|
||||
AffinityGroupVMMapDao _affinityGroupVMMapDao;
|
||||
|
||||
@Inject
|
||||
AffinityGroupDao _affinityGroupDao;
|
||||
|
||||
@Inject
|
||||
ActionEventUtils _eventUtils;
|
||||
|
||||
@Inject
|
||||
AccountDao _accountDao;
|
||||
|
||||
@Inject
|
||||
EventDao _eventDao;
|
||||
|
||||
@Inject
|
||||
DedicatedResourceDao _dedicatedDao;
|
||||
|
||||
private static long domainId = 5L;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws ConfigurationException {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
AccountVO acct = new AccountVO(200L);
|
||||
acct.setType(Account.ACCOUNT_TYPE_NORMAL);
|
||||
acct.setAccountName("user");
|
||||
acct.setDomainId(domainId);
|
||||
|
||||
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
|
||||
|
||||
CallContext.register(user, acct);
|
||||
|
||||
when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
|
||||
when(_processor.getType()).thenReturn("mock");
|
||||
when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
|
||||
|
||||
List<AffinityGroupProcessor> affinityProcessors = new ArrayList<AffinityGroupProcessor>();
|
||||
affinityProcessors.add(_processor);
|
||||
_affinityService.setAffinityGroupProcessors(affinityProcessors);
|
||||
|
||||
AffinityGroupVO group = new AffinityGroupVO("group1", "mock", "mock group", domainId, 200L, ControlledEntity.ACLType.Account);
|
||||
Mockito.when(_affinityGroupDao.persist(Mockito.any(AffinityGroupVO.class))).thenReturn(group);
|
||||
Mockito.when(_affinityGroupDao.findById(Mockito.anyLong())).thenReturn(group);
|
||||
Mockito.when(_affinityGroupDao.findByAccountAndName(Mockito.anyLong(), Mockito.anyString())).thenReturn(group);
|
||||
Mockito.when(_affinityGroupDao.lockRow(Mockito.anyLong(), anyBoolean())).thenReturn(group);
|
||||
Mockito.when(_affinityGroupDao.expunge(Mockito.anyLong())).thenReturn(true);
|
||||
Mockito.when(_eventDao.persist(Mockito.any(EventVO.class))).thenReturn(new EventVO());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
CallContext.unregister();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAffinityGroupTest() {
|
||||
when(_groupDao.isNameInUse(anyLong(), anyLong(), eq("group1"))).thenReturn(false);
|
||||
AffinityGroup group = _affinityService.createAffinityGroup("user", domainId, "group1", "mock", "affinity group one");
|
||||
assertNotNull("Affinity group 'group1' of type 'mock' failed to create ", group);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void invalidAffinityTypeTest() {
|
||||
AffinityGroup group = _affinityService.createAffinityGroup("user", domainId, "group1", "invalid", "affinity group one");
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void uniqueAffinityNameTest() {
|
||||
when(_groupDao.isNameInUse(anyLong(), anyLong(), eq("group1"))).thenReturn(true);
|
||||
AffinityGroup group2 = _affinityService.createAffinityGroup("user", domainId, "group1", "mock", "affinity group two");
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void deleteAffinityGroupInvalidIdTest() throws ResourceInUseException {
|
||||
when(_groupDao.findById(20L)).thenReturn(null);
|
||||
_affinityService.deleteAffinityGroup(20L, "user", domainId, "group1");
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void deleteAffinityGroupInvalidIdName() throws ResourceInUseException {
|
||||
when(_groupDao.findByAccountAndName(200L, "group1")).thenReturn(null);
|
||||
_affinityService.deleteAffinityGroup(null, "user", domainId, "group1");
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void deleteAffinityGroupNullIdName() throws ResourceInUseException {
|
||||
_affinityService.deleteAffinityGroup(null, "user", domainId, null);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void updateAffinityGroupVMRunning() throws ResourceInUseException {
|
||||
|
||||
UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false, domainId, 200L, 5L, "", "test", 1L);
|
||||
vm.setState(VirtualMachine.State.Running);
|
||||
when(_vmDao.findById(10L)).thenReturn(vm);
|
||||
|
||||
List<Long> affinityGroupIds = new ArrayList<Long>();
|
||||
affinityGroupIds.add(20L);
|
||||
|
||||
_affinityService.updateVMAffinityGroups(10L, affinityGroupIds);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = {AffinityGroupServiceImpl.class, ActionEventUtils.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class,
|
||||
type = FilterType.CUSTOM)}, useDefaultFilters = false)
|
||||
public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
|
||||
|
||||
@Bean
|
||||
public AccountDao accountDao() {
|
||||
return Mockito.mock(AccountDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountService accountService() {
|
||||
return Mockito.mock(AccountService.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupProcessor affinityGroupProcessor() {
|
||||
return Mockito.mock(AffinityGroupProcessor.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupDao affinityGroupDao() {
|
||||
return Mockito.mock(AffinityGroupDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupVMMapDao affinityGroupVMMapDao() {
|
||||
return Mockito.mock(AffinityGroupVMMapDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DedicatedResourceDao dedicatedResourceDao() {
|
||||
return Mockito.mock(DedicatedResourceDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountManager accountManager() {
|
||||
return Mockito.mock(AccountManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DomainManager domainManager() {
|
||||
return Mockito.mock(DomainManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EventDao eventDao() {
|
||||
return Mockito.mock(EventDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserVmDao userVMDao() {
|
||||
return Mockito.mock(UserVmDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserDao userDao() {
|
||||
return Mockito.mock(UserDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AffinityGroupDomainMapDao affinityGroupDomainMapDao() {
|
||||
return Mockito.mock(AffinityGroupDomainMapDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DomainDao domainDao() {
|
||||
return Mockito.mock(DomainDao.class);
|
||||
}
|
||||
|
||||
public static class Library implements TypeFilter {
|
||||
|
||||
@Override
|
||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||
ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue