// Sets-up the mounts for this instance.
private void setupMounts(RegistryService registryService, int tenantId) {
try {
boolean isSuperTenant = (tenantId == MultitenantConstants.SUPER_TENANT_ID);
Registry superTenantRegistry = registryService.getRegistry(
CarbonConstants.REGISTRY_SYSTEM_USERNAME);
Registry registry = registryService.getRegistry(
CarbonConstants.REGISTRY_SYSTEM_USERNAME, tenantId);
RegistryContext registryContext = superTenantRegistry.getRegistryContext();
for (Mount mount : registryContext.getMounts()) {
if (isFixedMount(registry, mount.getPath(), mount.getTargetPath(), isSuperTenant)) {
addFixedMount(tenantId, superTenantRegistry, mount.getPath());
continue;
}
if (!registry.resourceExists(mount.getPath())) {
if (isSuperTenant) {
superTenantRegistry.createLink(mount.getPath(), mount.getInstanceId(),
mount.getTargetPath());
} else {
createPseudoLink(registry, mount.getPath(), mount.getInstanceId(),
mount.getTargetPath());
addFixedMount(tenantId, superTenantRegistry, mount.getPath());
}
defineFixedMount(registry, mount.getPath(), isSuperTenant);
} else if (mount.isOverwrite()) {
registry.delete(mount.getPath());
if (isSuperTenant) {
superTenantRegistry.createLink(mount.getPath(), mount.getInstanceId(),
mount.getTargetPath());
} else {
createPseudoLink(registry, mount.getPath(), mount.getInstanceId(),
mount.getTargetPath());
addFixedMount(tenantId, superTenantRegistry, mount.getPath());
}
defineFixedMount(registry, mount.getPath(), isSuperTenant);
} else if (mount.isVirtual()) {
Resource r = registry.get(mount.getPath());
if (Boolean.toString(true).equals(r.getProperty(
RegistryConstants.REGISTRY_LINK))) {
log.error("Unable to create virtual remote mount at location: " +
mount.getPath() + ". Virtual remote mounts can only be created " +
"for physical resources.");
continue;
} else {
if (isSuperTenant) {
superTenantRegistry.createLink(mount.getPath(), mount.getInstanceId(),
mount.getTargetPath());
} else {
createPseudoLink(registry, mount.getPath(), mount.getInstanceId(),
mount.getTargetPath());
addFixedMount(tenantId, superTenantRegistry, mount.getPath());
}
defineFixedMount(registry, mount.getPath(), isSuperTenant);
}
} else {
log.error("Unable to create remote mount. A resource already exists at the " +
"given location: " + mount.getPath());
continue;
}
try {
if (!registry.resourceExists(mount.getPath())) {
log.warn("Target path does not exist for the given mount: " +
mount.getPath());
}
} catch (Exception e) {
log.warn("Target path does not exist for the given mount: " +