/**
* @return a List of {@link Cartridge}s.
*/
public List<Cartridge> getCartridgesList() {
FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
List<IaasProvider> iaasProviders = dataHolder.getIaasProviders();
if (iaasProviders == null) {
dataHolder.setIaasProviders((iaasProviders = new ArrayList<IaasProvider>()));
}
List<Cartridge> cartridges = new ArrayList<Cartridge>();
String xpath = CloudControllerConstants.CARTRIDGES_ELEMENT_XPATH;
// cartridges can be found from this XPATH
List<?> cartridgeNodes = getMatchingNodes(xpath, documentElement);
if (cartridgeNodes == null || cartridgeNodes.isEmpty()) {
// or from this XPATH
xpath = CloudControllerConstants.CARTRIDGE_ELEMENT_XPATH;
cartridgeNodes = getMatchingNodes(xpath, documentElement);
}
if (cartridgeNodes == null || cartridgeNodes.isEmpty()) {
log.warn("No cartridge found in this configuration file : " + xmlSource.getPath());
return cartridges;
}
for (Object obj : cartridgeNodes) {
if (obj instanceof OMNode) {
OMNode cartridgeNode = (OMNode) obj;
if (cartridgeNode.getType() == OMNode.ELEMENT_NODE) {
OMElement cartridgeElement = (OMElement) cartridgeNode;
// retrieve Attributes of a Cartridge definition
String type = cartridgeElement.getAttributeValue(new QName(
CloudControllerConstants.TYPE_ATTR));
String host = cartridgeElement.getAttributeValue(new QName(
CloudControllerConstants.HOST_ATTR));
String provider = cartridgeElement.getAttributeValue(new QName(
CloudControllerConstants.PROVIDER_ATTR));
String version =
cartridgeElement.getAttributeValue(new QName(
CloudControllerConstants.VERSION_ATTR));
boolean multiTenant = Boolean.valueOf(cartridgeElement.getAttributeValue(new QName(
CloudControllerConstants.MULTI_TENANT_ATTR)));
Cartridge aCartridge;
if ((aCartridge = dataHolder.getCartridge(type)) == null) {
aCartridge = new Cartridge(type, host, provider, version, multiTenant);
}
// read displayName
Iterator<?> itName =
cartridgeElement.getChildrenWithName(new QName(
CloudControllerConstants.DISPLAY_NAME_ELEMENT));
if (itName.hasNext()) {
OMElement name = (OMElement) itName.next();
aCartridge.setDisplayName(name.getText());
}
// read description
Iterator<?> it =
cartridgeElement.getChildrenWithName(new QName(
CloudControllerConstants.DESCRIPTION_ELEMENT));
if (it.hasNext()) {
OMElement desc = (OMElement) it.next();
aCartridge.setDescription(desc.getText());
}
// load properties of this cartridge
loadProperties(cartridgeElement, aCartridge.getProperties());
// retrieve the list of IaaS providers
List<?> iaasProviderNodes = getMatchingNodes(xpath + CloudControllerConstants.IAAS_PROVIDER_ELEMENT_XPATH,
cartridgeElement);
getIaasProviders(iaasProviders, cartridgeElement.toString(), aCartridge, iaasProviderNodes);
// load dirs
List<?> deploymentNodes = getMatchingNodes(xpath + CloudControllerConstants.DEPLOYMENT_ELEMENT_XPATH,
cartridgeElement);
setDeploymentDirs(cartridgeElement.toString(), aCartridge, deploymentNodes);
// load port mappings
List<?> portMappingNodes =
getMatchingNodes(xpath +
CloudControllerConstants.PORT_MAPPING_ELEMENT_XPATH,
cartridgeElement);
getPortMappings(cartridgeElement.toString(), aCartridge, portMappingNodes);
// load appTypes
List<?> appTypesNodes =
getMatchingNodes(xpath +
CloudControllerConstants.APP_TYPES_ELEMENT_XPATH,
cartridgeElement);
getAppTypes(cartridgeElement.toString(), aCartridge, appTypesNodes);
cartridges.add(aCartridge);
if (dataHolder.getCartridge(type) == null) {
dataHolder.addCartridge(aCartridge);
}
}
}
}