throw new ADCException("An error occurred in subscribing process");
}
}
public static Cartridge populateCartridgeInfo(CartridgeInfo cartridgeInfo, CartridgeSubscription sub, String[] ips, String tenantDomain) throws ADCException {
Cartridge cartridge = new Cartridge();
if (ips != null && ips.length > 0) {
if (log.isDebugEnabled()) {
log.debug("Found IPs: " + Arrays.toString(ips) + " for " + cartridgeInfo.getType() + ", "
+ sub.getAlias());
}
if (CartridgeConstants.DATA_CARTRIDGE_PROVIDER.equals(sub.getProvider())) {
// FIXME Temporary fix for SPI-301
cartridge.setIp(ips[ips.length - 1]);
if (sub.getDataCartridge() != null) {
if (log.isDebugEnabled()) {
log.debug("Data Cartridge Info: " + sub.getDataCartridge().getUserName());
}
cartridge.setPassword(sub.getDataCartridge().getPassword());
cartridge.setDbUserName(sub.getDataCartridge().getUserName());
}
}
if (cartridgeInfo.getMultiTenant()) { // TODO refactor logic for carbon cartridges.
cartridge.setStatus(CartridgeConstants.ACTIVE);
cartridge.setActiveInstances(ips.length);
} else {
Map<String, String> instanceIpMap;
try {
instanceIpMap = PersistenceManager.getCartridgeInstanceInfo(ips, sub.getClusterDomain(),
sub.getClusterSubdomain());
cartridge.setActiveInstances(Collections.frequency(instanceIpMap.values(),
CartridgeConstants.ACTIVE));
cartridge.setStatus(checkCartridgeStatus(instanceIpMap));
} catch (Exception e) {
throw new ADCException("Error checking cartridge status");
}
if(cartridgeInfo.getProvider().equalsIgnoreCase(CartridgeConstants.PROVIDER_NAME_WSO2)) {
List<Member> members = getMemberInstances(sub.getClusterDomain(), sub.getClusterSubdomain());
if(members != null) {
int activeInstancesCount = 0;
for (Member member : members) {
if (member != null && member.isActive() && member.getDomain().equals(sub.getClusterDomain())) {
cartridge.setStatus(CartridgeConstants.ACTIVE);
activeInstancesCount ++;
}
}
cartridge.setActiveInstances(activeInstancesCount);
}
}
}
} else {
log.warn("IPs have not returned through Topology Management for " + sub.getAlias());
cartridge.setStatus(CartridgeConstants.SUBSCRIBED);
}
cartridge.setDisplayName(cartridgeInfo.getDisplayName());
cartridge.setDescription(cartridgeInfo.getDescription());
cartridge.setVersion(cartridgeInfo.getVersion());
cartridge.setMultiTenant(cartridgeInfo.getMultiTenant());
List<String> accessURLs = new ArrayList<String>();
if (cartridgeInfo.getPortMappings() != null) {
for (org.apache.stratos.cloud.controller.util.xsd.PortMapping portMapping : cartridgeInfo
.getPortMappings()) {
if (portMapping != null) {
try {
int port = Integer.parseInt(portMapping.getProxyPort());
String protocol = portMapping.getProtocol();
if ("http".equals(protocol) && port == 80) {
port = -1;
} else if ("https".equals(protocol) && port == 443) {
port = -1;
}
String file = "";
if (CartridgeConstants.PROVIDER_NAME_WSO2.equals(cartridgeInfo.getProvider()) && !cartridgeInfo.getMultiTenant()) {
// Carbon Private Jet Cartridges
file = "/t/" + tenantDomain;
}
URL serverURL = new URL(protocol, sub.getHostName(), port, file);
accessURLs.add(serverURL.toExternalForm());
} catch (MalformedURLException e) {
if (log.isErrorEnabled()) {
log.error("Error getting access URL for " + cartridgeInfo.getType(), e);
}
} catch (NumberFormatException e) {
if (log.isErrorEnabled()) {
log.error("Error getting port of access URL for " + cartridgeInfo.getType(), e);
}
}
}
}
}
cartridge.setAccessURLs(accessURLs.toArray(new String[accessURLs.size()]));
cartridge.setCartridgeAlias(sub.getAlias());
cartridge.setCartridgeType(sub.getCartridge());
cartridge.setHostName(sub.getHostName());
cartridge.setPolicy(sub.getPolicy());
Policy policy = PolicyHolder.getInstance().getPolicy(sub.getPolicy());
if (policy != null) {
cartridge.setPolicyDescription(policy.getDescription());
}
cartridge.setProvider(sub.getProvider());
cartridge.setMappedDomain(sub.getMappedDomain());
if (sub.getRepository() != null) {
cartridge.setRepoURL(convertRepoURL(sub.getRepository().getRepoName()));
}
return cartridge;
}