OVFEnvelopeUtils.getSection(envelope, DiskSectionType.class);
if (diskSectionType.getDisk().size() != 1)
{
// more than one disk in disk section
throw new AMException(AMError.TEMPLATE_INVALID_MULTIPLE_DISKS);
}
else
{
int references = 0;
for (FileType fileType : envelope.getReferences().getFile())
{
fileIdToFileType.put(fileType.getId(), fileType);
if (diskSectionType.getDisk().get(0).getFileRef().equals(fileType.getId()))
{
references++;
}
}
if (references != 1)
{
// file referenced in diskSection isn't found in file references or found more
// than one
throw new AMException(AMError.TEMPLATE_INVALID_MULTIPLE_FILES);
}
}
// Create a hash
for (VirtualDiskDescType virtualDiskDescType : diskSectionType.getDisk())
{
diskIdToDiskFormat.put(virtualDiskDescType.getDiskId(), virtualDiskDescType);
}
// /
ContentType content = OVFEnvelopeUtils.getTopLevelVirtualSystemContent(envelope);
if (content instanceof VirtualSystemCollectionType)
{
throw new EmptyEnvelopeException("Current OVF description document includes a VirtualSystemCollection, "
+ "abicloud only deal with single virtual system based OVFs");
}
VirtualSystemType vsystem = (VirtualSystemType) content;
VirtualHardwareSectionType hardwareSectionType;
Integer cpu = null;
Long hd = null;
Long ram = null;
try
{
hardwareSectionType =
OVFEnvelopeUtils.getSection(vsystem, VirtualHardwareSectionType.class);
}
catch (InvalidSectionException e)
{
throw new SectionNotPresentException("VirtualHardware on a virtualSystem", e);
}
for (RASDType rasdType : hardwareSectionType.getItem())
{
ResourceType resourceType = rasdType.getResourceType();
if (resourceType == null) // empty rasd element
{
continue;
}
int resTnumeric = Integer.parseInt(resourceType.getValue());
// Get the information on the ram
if (CIMResourceTypeEnum.Processor.getNumericResourceType() == resTnumeric)
{
try
{
String cpuVal = rasdType.getVirtualQuantity().getValue().toString();
cpu = Integer.parseInt(cpuVal);
}
catch (Exception e)
{
throw new AMException(AMError.TEMPLATE_INVALID,
"Invalid CPU virtualQuantity");
}
}
else if (CIMResourceTypeEnum.Memory.getNumericResourceType() == resTnumeric)
{
try
{
BigInteger ramVal = rasdType.getVirtualQuantity().getValue();
ram = ramVal.longValue();
}
catch (Exception e)
{
throw new AMException(AMError.TEMPLATE_INVALID,
"Invalid RAM virtualQuantity");
}
}
else if (CIMResourceTypeEnum.Disk_Drive.getNumericResourceType() == resTnumeric)
{
// HD requirements are extracted from the associated Disk on ''hostResource''
String diskId = getVirtualSystemDiskId(rasdType.getHostResource());
if (!diskIdToDiskFormat.containsKey(diskId))
{
throw new RequiredAttributeException("Virtual System makes reference to an undeclared disk "
+ diskId);
}
VirtualDiskDescType diskDescType = diskIdToDiskFormat.get(diskId);
String capacity = diskDescType.getCapacity();
hd = Long.parseLong(capacity);
}
}// rasd
if (cpu == null)
{
throw new RequiredAttributeException("Not CPU RASD element found on the envelope");
}
if (ram == null)
{
throw new RequiredAttributeException("Not RAM RASD element found on the envelope");
}
if (hd == null)
{
throw new RequiredAttributeException("Not HD RASD element found on the envelope");
}
}
catch (AMException amException)
{
throw amException;
}
catch (Exception e)
{
throw new AMException(AMError.TEMPLATE_INVALID, e);
}
return envelope;
}