Skip to content

Commit

Permalink
Merge branch 'master' of github.com:abiquo/abiquo
Browse files Browse the repository at this point in the history
Conflicts:
	api/src/main/resources/springresources/security-beans.xml
  • Loading branch information
Jaume Devesa committed Apr 24, 2012
2 parents 7866808 + e8874cd commit f006b41
Show file tree
Hide file tree
Showing 36 changed files with 363 additions and 223 deletions.
2 changes: 1 addition & 1 deletion aimstub/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.abiquo.abicloud</groupId>
<artifactId>platform</artifactId>
<version>2.0-HF1-SNAPSHOT</version>
<version>2.0-HF2-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion am/pom.xml
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.abiquo.abicloud</groupId>
<artifactId>platform</artifactId>
<version>2.0-HF1-SNAPSHOT</version>
<version>2.0-HF2-SNAPSHOT</version>
</parent>
<!-- Dependences -->
<dependencies>
Expand Down
Expand Up @@ -97,7 +97,7 @@ public TemplatesStateDto getTemplateStatus(
TemplatesStateDto list = new TemplatesStateDto();
for (TemplateStateDto stt : ErepoFactory.getRepo(idEnterprise).getTemplateStates())
{
if (state != null || stt.getStatus().equals(state))
if (state == null || stt.getStatus().equals(state))
{
list.getCollection().add(stt);
}
Expand Down
Expand Up @@ -114,6 +114,14 @@ public EnterpriseRepositoryDto getRepository(final Integer idEnterprise)
return response.getEntity(EnterpriseRepositoryDto.class);
}

public void refreshRepository(final Integer idEnterprise) throws AMClientException
{
ClientResponse response =
repository(idEnterprise).accept(MediaType.APPLICATION_XML).post(null);

checkResponseErrors(response);
}

public void checkService() throws AMClientException
{
ClientResponse response = check()//
Expand Down
Expand Up @@ -51,11 +51,12 @@ public class CheckServlet extends AbstractCheckServlet
private final static String MOUNT_FILE = "/etc/mtab";

/** The expected file mark in the repositoryl. */
private final static String REPO_MARK = AMConfiguration.getRepositoryPath()
+ ".abiquo_repository";
private final static String REPO_MARK =
AMConfiguration.getRepositoryPath() + ".abiquo_repository";

private final boolean DO_CHECK = Boolean.parseBoolean(System.getProperty(
"abiquo.appliancemanager.checkMountedRepository", "true"));
private final boolean DO_CHECK =
Boolean.parseBoolean(System.getProperty("abiquo.appliancemanager.checkMountedRepository",
"true"));

@Override
protected boolean check() throws Exception
Expand Down Expand Up @@ -106,16 +107,16 @@ public synchronized boolean checkRedis()

public synchronized boolean checkRepositoryMounted()
{
final String repositoryLocatino =
final String repositoryLocation =
FilenameUtils.normalizeNoEndSeparator(AMConfiguration.getRepositoryLocation());
final String repositoryMountPoint =
FilenameUtils.normalizeNoEndSeparator(AMConfiguration.getRepositoryPath());

if (repositoryLocatino.startsWith("localhost")
|| repositoryLocatino.startsWith("127.0.0.1"))
if (repositoryLocation.startsWith("localhost")
|| repositoryLocation.startsWith("127.0.0.1"))
{
LOGGER.warn("Can't validate ''abiquo.appliancemanager.repositoryLocation'' {}."
+ " Its a local repository", repositoryLocatino);
LOGGER.warn("Cannot validate ''abiquo.appliancemanager.repositoryLocation'' {}."
+ " It is a local repository", repositoryLocation);
return true;
}

Expand All @@ -127,10 +128,10 @@ public synchronized boolean checkRepositoryMounted()

for (String line = mountReader.readLine(); line != null; line = mountReader.readLine())
{
if (line.contains(repositoryLocatino))
if (line.contains(repositoryLocation))
{
final String[] parts = line.split(" ");
if (repositoryLocatino.equals(FilenameUtils.normalizeNoEndSeparator(parts[0]))
if (repositoryLocation.equals(FilenameUtils.normalizeNoEndSeparator(parts[0]))
&& repositoryMountPoint.equalsIgnoreCase(FilenameUtils
.normalizeNoEndSeparator(parts[1])))
{
Expand All @@ -140,7 +141,7 @@ public synchronized boolean checkRepositoryMounted()
{
LOGGER.warn(
"Repository location {} present but not mounted on the expected path {} \n"
+ line, repositoryLocatino, repositoryMountPoint);
+ line, repositoryLocation, repositoryMountPoint);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>com.abiquo.abicloud</groupId>
<artifactId>platform</artifactId>
<version>2.0-HF1-SNAPSHOT</version>
<version>2.0-HF2-SNAPSHOT</version>
</parent>
<!-- Set dependences -->
<dependencies>
Expand Down
19 changes: 11 additions & 8 deletions api/src/main/java/com/abiquo/api/exceptions/APIError.java
Expand Up @@ -378,8 +378,8 @@ public enum APIError
"RS-11",
"Cannot delete a Virtual System Monitor Service. There are virtual machines deployed."), REMOTE_SERVICE_WRONG_URL(
"RS-12", "The URL supplied is not valid"), REMOTE_SERVICE_DHCP_WRONG_URI("RS-13",
"The URI of the DHCP service is invalid"), REMOTE_SERVICE_DATACENTER_UUID_NOT_FOUND("RS-14",
"The remote service does not have the *abiquo.datacenter.id* property set"), REMOTE_SERVICE_DATACENTER_UUID_INCONSISTENT(
"The URI of the DHCP service is invalid"), REMOTE_SERVICE_DATACENTER_UUID_NOT_FOUND(
"RS-14", "The remote service does not have the *abiquo.datacenter.id* property set"), REMOTE_SERVICE_DATACENTER_UUID_INCONSISTENT(
"RS-15",
"The remote service is configured with a different datacenter UUID, please adjust the *abiquo.datacenter.id* property of the remote service."), REMOTE_SERVICE_UNDEFINED_PORT(
"RS-16", "A port must be defined in the URI"), REMOTE_SERVICE_NON_POOLABLE("RS-17",
Expand All @@ -390,7 +390,8 @@ public enum APIError
//
AM_CLIENT("AM-0", "Failed Appliance Manager communication"), AM_TIMEOUT("AM-1",
"Timeout during Appliance Manager communication"), AM_UNAVAILABE("AM-2",
"AM service unavailable; please check the URL of the service."), AM_FAILED_REQUEST("AM-3",
"AM service unavailable; please check the URL of the service."), AM_FAILED_REQUEST(
"AM-3",
"Failed Appliance Manager request. "
+ "It is possible that the repositoryLocation property is not correct, NFS is not available or NFS privileges do not allow access to the server."),

Expand All @@ -414,7 +415,8 @@ public enum APIError
// VIRTUAL IMAGE
VIMAGE_INVALID_ALLOCATION_UNITS("VIMAGE-INVALID-OVF-ALLOCATION-INITS",
"Virtual machine template cannot be added due to invalid allocation units"), VMTEMPLATE_SYNCH_DC_REPO(
"VIMAGE-SYNCH-DATACENTER-REPOSITORY", "Cannot obtain downloaded OVF in the datacenter"), VIMAGE_DATACENTER_REPOSITORY_NOT_FOUND(
"VIMAGE-SYNCH-DATACENTER-REPOSITORY",
"Cannot obtain downloaded templates in the datacenter repository"), VIMAGE_DATACENTER_REPOSITORY_NOT_FOUND(
"DATACENTER-REPOSITORY-NOT-CREATED",
"Datacenter Repository not configured; check Datacenter's Appliance Manager. Contact Infrastructure Administrator"), VMTEMPLATE_REPOSITORY_CHANGED(
"VIMAGE-REPOSITORY-CHANGED", "Datacenter repository location has changed"), VIMAGE_AM_DOWN(
Expand Down Expand Up @@ -611,7 +613,7 @@ public enum APIError
"CHEF-5", "The node could not be updated on the Chef Server. "
+ "Please contact the Administrator."), CHEF_CANNOT_CONNECT("CHEF-6",
"Could not connect to the Chef server. Please contact the Administrator."), CHEF_INVALID_ENTERPRISE_DATA(
"CHEF-7", "Could not connect to the Chef server with the given Validator and Admin data. "
"CHEF-7", "Could not connect to the Chef server with the given Admin data. "
+ "Please verify the credentials"), CHEF_INVALID_ENTERPRISE("CHEF-8",
"The enterprise is not configured to use Chef"), CHEF_INVALID_VIRTUALMACHINE("CHEF-9",
"The virtual machine cannot use Chef. "
Expand All @@ -620,7 +622,8 @@ public enum APIError
"The validator certificate supplied is not a valid private key. Please verify the key format."), CHEF_INVALID_CLIENT_KEY(
"CHEF-11",
"The provided admin certificate is not a valid private key. Please verify the key format."), CHEF_MALFORMED_URL(
"CHEF-12", "The provided chef server URL is not well formed."),
"CHEF-12", "The provided chef server URL is not well formed."), CHEF_CLIENT_DOES_NOT_EXIST(
"CHEF-13", "The validator client supplied does not exist"),

// Parsing links
LINKS_INVALID_LINK("LNK-0", "Invalid link. Check documentation"), LINKS_ONLY_ACCEPTS_ONE_LINK(
Expand Down Expand Up @@ -765,8 +768,8 @@ public int compare(final APIError err1, final APIError err2)
// Outputs all errors in wiki table format
for (APIError error : errors)
{
System.out.println(String.format("| %s | %s | %s |", error.code, error.message, error
.name()));
System.out.println(String.format("| %s | %s | %s |", error.code, error.message,
error.name()));
}

System.out.println("\n ************ Flex client labels ************** \n");
Expand Down
Expand Up @@ -477,7 +477,7 @@ public void isStonithUp(@PathParam(DatacenterResource.DATACENTER) final Integer
@PathParam(MachineResource.MACHINE) final Integer machineId,
@QueryParam("ip") @NotNull final String ip, @QueryParam("user") @NotNull final String user,
@QueryParam("password") @NotNull final String password,
@QueryParam("port") @NotNull final Integer port, @Context final IRESTBuilder restBuilder)
@QueryParam("port") final Integer port, @Context final IRESTBuilder restBuilder)
throws Exception
{
infraService.isStonithUp(datacenterId, ip, user, password, port);
Expand Down
Expand Up @@ -67,6 +67,14 @@ public class CategoriesResource extends AbstractResource
* Returns all categories
*
* @title Retrieve all categories
* @wiki Returns the global categories by default. If you supply the id of a enterprise, the
* global categories and the local categories of the the given id will be retrieved. If no
* id is supplied, global categories will be retrieved. This feature is available from
* version 2.0-HF1
* @param idEnterprise If you supply the id of a enterprise, the global categories and the local
* categories of the the given enterprise will be retrieved. If no id is supplied,
* global categories will be retrieved.
* @since 2.0-HF1
* @param restBuilder a Context-injected object to create the links of the Dto
* @return a {CategoriesDto} object with all categories
* @throws Exception
Expand All @@ -91,8 +99,12 @@ public CategoriesDto getCategory(
}

/**
* Creates a category and returns it after creation
*
* @wiki Creates a category and returns it after creation. If you provide a link to the
* enterprise it will create a local category, and without any link in the dto it will try
* to create a global category. To create global category user must have the role
* APPLIB_MANAGE_GLOBAL_CATEGORIES. The division in local and global categories is
* available from versin 2.0-HF1
* @since 2.0-HF1
* @param categoryDto category to create
* @param builder a Context-injected object to create the links of the Dto
* @return a {CategoryDto} with the created category
Expand Down
79 changes: 61 additions & 18 deletions api/src/main/java/com/abiquo/api/services/NetworkService.java
Expand Up @@ -21,6 +21,9 @@

package com.abiquo.api.services;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
Expand Down Expand Up @@ -393,15 +396,23 @@ public VLANNetwork createPrivateNetwork(final Integer vdcId, final VLANNetwork n
for (DhcpOption dhcpOption : newVlan.getDhcpOption())
{
dhcpOption.setOption(121);
datacenterRepo.insertDhcpOption(dhcpOption);
DhcpOption dhcpOption2 =
new DhcpOption(249,
dhcpOption.getGateway(),
dhcpOption.getNetworkAddress(),
dhcpOption.getMask(),
dhcpOption.getNetmask());
datacenterRepo.insertDhcpOption(dhcpOption2);
opts.add(dhcpOption2);
dhcpOption.setMask(getMaskbyNetMask(dhcpOption.getNetmask()));
if (dhcpOption.getMask() != 0)
{
datacenterRepo.insertDhcpOption(dhcpOption);
DhcpOption dhcpOption2 =
new DhcpOption(249,
dhcpOption.getGateway(),
dhcpOption.getNetworkAddress(),
dhcpOption.getMask(),
dhcpOption.getNetmask());
datacenterRepo.insertDhcpOption(dhcpOption2);
opts.add(dhcpOption2);
}
else
{
opts.remove(dhcpOption);
}
}
newVlan.setDhcpOption(opts);
// Before to insert the new VLAN, check if we want the vlan as the default one. If it is,
Expand Down Expand Up @@ -1217,15 +1228,23 @@ public VLANNetwork updatePrivateNetwork(final Integer vdcId, final Integer vlanI
for (DhcpOption dhcpOption : newNetwork.getDhcpOption())
{
dhcpOption.setOption(121);
datacenterRepo.insertDhcpOption(dhcpOption);
DhcpOption dhcpOption2 =
new DhcpOption(249,
dhcpOption.getGateway(),
dhcpOption.getNetworkAddress(),
dhcpOption.getMask(),
dhcpOption.getNetmask());
datacenterRepo.insertDhcpOption(dhcpOption2);
opts.add(dhcpOption2);
dhcpOption.setMask(getMaskbyNetMask(dhcpOption.getNetmask()));
if (dhcpOption.getMask() != 0)
{
datacenterRepo.insertDhcpOption(dhcpOption);
DhcpOption dhcpOption2 =
new DhcpOption(249,
dhcpOption.getGateway(),
dhcpOption.getNetworkAddress(),
dhcpOption.getMask(),
dhcpOption.getNetmask());
datacenterRepo.insertDhcpOption(dhcpOption2);
opts.add(dhcpOption2);
}
else
{
opts.remove(dhcpOption);
}
}
oldNetwork.setDhcpOption(opts);

Expand Down Expand Up @@ -1418,4 +1437,28 @@ protected void storeIPs(final Datacenter datacenter, final VirtualDatacenter vdc

}

private Integer getMaskbyNetMask(final String netmask)
{

Inet4Address address;
try
{
address = (Inet4Address) InetAddress.getByName(netmask);
byte[] values = address.getAddress();
int hex = values[0] << 24 | values[1] << 16 | values[2] << 8 | values[3] << 0;

Integer mask = Integer.bitCount(hex);
if (mask < 32)
{
return mask;
}
}
catch (UnknownHostException e)
{
// invalid netmask
}

return 0;
}

}
Expand Up @@ -213,6 +213,7 @@ else if (appslibraryRep.findCategoryByName(category.getName(), null) != null)
}
old.setName(category.getName());
old.setErasable(category.isErasable());
old.setEnterprise(newCat.getEnterprise());

validate(old);
appslibraryRep.updateCategory(old);
Expand Down
Expand Up @@ -254,6 +254,8 @@ public List<TemplateDto> refreshRepository(final Integer enterpriseId,

try
{
amClient.refreshRepository(enterpriseId);

List<TemplateStateDto> downloads =
amClient.getTemplatesState(enterpriseId, TemplateStatusEnumType.DOWNLOAD)
.getCollection();
Expand Down
Expand Up @@ -376,13 +376,6 @@ protected void primaryDiskDefinitionConfiguration(final VirtualMachine virtualMa
final String path = conversion != null ? conversion.getTargetPath() : vmtemplate.getPath();
final DiskControllerType cntrlType = getDiskController(htype, true, false);

if (cntrlType != null && cntrlType == DiskControllerType.SCSI
&& format == DiskFormatType.VMDK_SPARSE)
{
addConflictErrors(APIError.VIRTUAL_MACHINE_ESXI_INCOMPATIBLE_DISK_CONTROLLER);
flushErrors();
}

String url = "";
if (virtualMachine.getVirtualMachineTemplate().getRepository() != null) // repo null when
// imported.
Expand Down
4 changes: 0 additions & 4 deletions api/src/main/java/com/abiquo/api/util/RESTBuilder.java
Expand Up @@ -726,10 +726,6 @@ public List<RESTLink> buildVirtualDatacenterLinks(final VirtualDatacenter vdc,
VirtualDatacenterResource.VIRTUAL_DATACENTER_GET_IPS_PATH,
VirtualDatacenterResource.VIRTUAL_DATACENTER_GET_IPS_REL, params,
IpPoolManagementDto.BASE_MEDIA_TYPE));
links.add(builder.buildRestLink(VirtualDatacenterResource.class,
VirtualDatacenterResource.VIRTUAL_DATACENTER_DHCP_INFO_PATH,
VirtualDatacenterResource.VIRTUAL_DATACENTER_DHCP_INFO_REL, params,
MediaType.TEXT_PLAIN));
RESTLink getVlanLink =
builder.buildRestLink(VirtualDatacenterResource.class,
VirtualDatacenterResource.DEFAULT_VLAN_PATH,
Expand Down

0 comments on commit f006b41

Please sign in to comment.