org.springframework.cloud.CloudFactory Java Examples

The following examples show how to use org.springframework.cloud.CloudFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCloudServiceConnectorFactory.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) getBeanFactory();

	if (cloud == null) {
		if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
			beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
		}
		CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
		cloud = cloudFactory.getCloud();
	}
	if (!StringUtils.hasText(serviceId)) {
		List<? extends ServiceInfo> infos = cloud.getServiceInfos(serviceConnectorType);
		if (infos.size() != 1) {
			throw new CloudException("Expected 1 service matching " + serviceConnectorType.getName() + " type, but found "
				+ infos.size());
		}
		serviceId = infos.get(0).getId();
	}

	super.afterPropertiesSet();
}
 
Example #2
Source File: ObjectStoreFileStorageFactoryBean.java    From multiapps-controller with Apache License 2.0 6 votes vote down vote up
private ObjectStoreServiceInfo getServiceInfo() {
    if (StringUtils.isEmpty(serviceName)) {
        LOGGER.warn("service name not specified in config files");
        return null;
    }
    try {
        CloudFactory cloudFactory = new CloudFactory();
        Cloud cloud = cloudFactory.getCloud();
        ServiceInfo serviceInfo = cloud.getServiceInfo(serviceName);
        if (serviceInfo instanceof ObjectStoreServiceInfo) {
            return (ObjectStoreServiceInfo) serviceInfo;
        }
        LOGGER.warn("Service instance did not match allowed label and plans.");
    } catch (CloudException e) {
        LOGGER.warn(MessageFormat.format("Failed to detect service info for service \"{0}\"!", serviceName), e);
    }
    return null;
}
 
Example #3
Source File: ProductApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/** 
 * Returns cloud object if the application runs on cloud environment
 * 
 * @return cloud object if the application runs on cloud environment
 */
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example #4
Source File: CloudScanHelper.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
private void initializeCloud(BeanDefinitionRegistry registry) {
	if (cloud != null) {
		return;
	}

	ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) registry;

	if(beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
		beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
	}
	CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
	cloud = cloudFactory.getCloud();
}
 
Example #5
Source File: CloudPropertiesFactoryBean.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	ConfigurableListableBeanFactory listableBeanFactory = (ConfigurableListableBeanFactory) beanFactory;
	
	if (cloud == null) {
		if(listableBeanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
			listableBeanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME , new CloudFactory());
		}
		CloudFactory cloudFactory = listableBeanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
		cloud = cloudFactory.getCloud();
	}
}
 
Example #6
Source File: SpringApplicationContextInitializer.java    From spring-music with Apache License 2.0 5 votes vote down vote up
private Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException ce) {
        return null;
    }
}
 
Example #7
Source File: AbstractWebApplicationInitializer.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
protected Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException ce) {
        return null;
    }
}
 
Example #8
Source File: SsoServiceCredentialsListener.java    From spring-cloud-sso-connector with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    if (cloud != null) return;
    try {
        cloud = new CloudFactory().getCloud();
    } catch (CloudException e) {
        return; // not running on a known cloud environment, so nothing to do
    }

    for (ServiceInfo serviceInfo : cloud.getServiceInfos()) {
        if (serviceInfo instanceof SsoServiceInfo) {
            Map<String, Object> map = new HashMap<>();
            SsoServiceInfo ssoServiceInfo = (SsoServiceInfo) serviceInfo;
            map.put("security.oauth2.client.clientId", ssoServiceInfo.getClientId());
            map.put("security.oauth2.client.clientSecret", ssoServiceInfo.getClientSecret());
            map.put("security.oauth2.client.accessTokenUri", ssoServiceInfo.getAuthDomain() + "/oauth/token");
            map.put("security.oauth2.client.userAuthorizationUri", ssoServiceInfo.getAuthDomain() + "/oauth/authorize");
            map.put("ssoServiceUrl", ssoServiceInfo.getAuthDomain());
            map.put("security.oauth2.resource.userInfoUri", ssoServiceInfo.getAuthDomain() + "/userinfo");
            map.put("security.oauth2.resource.tokenInfoUri", ssoServiceInfo.getAuthDomain() + "/check_token");
            map.put("security.oauth2.resource.jwk.key-set-uri", ssoServiceInfo.getAuthDomain() + "/token_keys");
            MapPropertySource mapPropertySource = new MapPropertySource("vcapPivotalSso", map);

            event.getEnvironment().getPropertySources().addFirst(mapPropertySource);
        }
    }
}
 
Example #9
Source File: TestRestController.java    From bluemix-cloud-connectors with Apache License 2.0 5 votes vote down vote up
private Cloud getCloud() {
  try {
    CloudFactory cloudFactory = new CloudFactory();
    return cloudFactory.getCloud();
  } catch (CloudException ce) {
    return null;
  }
}
 
Example #10
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException e) {
        return null;
    }
}
 
Example #11
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException e) {
        return null;
    }
}
 
Example #12
Source File: FileSystemFileStorageFactoryBean.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private String getStoragePath(String serviceName) {
    if (StringUtils.isEmpty(serviceName)) {
        LOGGER.warn(Messages.FILE_SYSTEM_SERVICE_NAME_IS_NOT_SPECIFIED);
        return null;
    }
    try {
        CloudFactory cloudFactory = new CloudFactory();
        Cloud cloud = cloudFactory.getCloud();
        FileSystemServiceInfo serviceInfo = (FileSystemServiceInfo) cloud.getServiceInfo(serviceName);
        return serviceInfo.getStoragePath();
    } catch (CloudException e) {
        LOGGER.warn(MessageFormat.format(Messages.FAILED_TO_DETECT_FILE_SERVICE_STORAGE_PATH, serviceName), e);
    }
    return null;
}
 
Example #13
Source File: MicrometerConfiguration.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private DynatraceServiceInfo getDynatraceServiceInfo() {
    String serviceName = DynatraceServiceInfoCreator.DEFAULT_DYNATRACE_SERVICE_ID;
    try {
        CloudFactory cloudFactory = new CloudFactory();
        Cloud cloud = cloudFactory.getCloud();
        ServiceInfo serviceInfo = cloud.getServiceInfo(serviceName);
        if (serviceInfo instanceof DynatraceServiceInfo) {
            return (DynatraceServiceInfo) serviceInfo;
        }
        LOGGER.warn("Service instance did not match allowed name and type.");
    } catch (CloudException e) {
        LOGGER.warn(MessageFormat.format("Failed to detect service info for service \"{0}\"!", serviceName), e);
    }
    return null;
}
 
Example #14
Source File: WorkerContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example #15
Source File: EnterpriseMessagingConfig.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
@Bean
public MessagingServiceFactory getMessagingServiceFactory() {
    ServiceConnectorConfig config = null; // currently there are no configurations for the MessagingService supported
    Cloud cloud = new CloudFactory().getCloud();
    // get the MessagingService via the service connector
    MessagingService messagingService = cloud.getSingletonServiceConnector(MessagingService.class, config);
    if (messagingService == null) {
        throw new IllegalStateException("Unable to create the MessagingService.");
    }
    return MessagingServiceFactoryCreator.createFactory(messagingService);
}
 
Example #16
Source File: EnterpriseMessagingConfig.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
@Bean
public MessagingServiceFactory getMessagingServiceFactory() {
    ServiceConnectorConfig config = null; // currently there are no configurations for the MessagingService supported
    Cloud cloud = new CloudFactory().getCloud();
    // get the MessagingService via the service connector
    MessagingService messagingService = cloud.getSingletonServiceConnector(MessagingService.class, config);
    if (messagingService == null) {
        throw new IllegalStateException("Unable to create the MessagingService.");
    }
    return MessagingServiceFactoryCreator.createFactory(messagingService);
}
 
Example #17
Source File: SaleApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/** 
 * Returns cloud object if the application runs on cloud environment
 * 
 * @return cloud object if the application runs on cloud environment
 */
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example #18
Source File: TaxApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/**
 * Returns cloud object if the application runs on cloud environment
 * 
 * @return cloud object if the application runs on cloud environment
 */
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example #19
Source File: CustomerApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/** 
 * Returns cloud object if the application runs on cloud environment
 * 
 * @return cloud object if the application runs on cloud environment
 */
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example #20
Source File: RabbitServiceAutoConfiguration.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public Cloud cloud() {
	return new CloudFactory().getCloud();
}
 
Example #21
Source File: CloudDataSourceFactoryBean.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
protected Cloud getSpringCloud() {
    return new CloudFactory().getCloud();
}
 
Example #22
Source File: RabbitServiceConfiguration.java    From spring-bus with Apache License 2.0 4 votes vote down vote up
@Bean
public Cloud cloud() {
  return new CloudFactory().getCloud();
}
 
Example #23
Source File: RedisServiceConfiguration.java    From spring-bus with Apache License 2.0 4 votes vote down vote up
@Bean
public Cloud cloud() {
  return new CloudFactory().getCloud();
}
 
Example #24
Source File: DataSourceCloudConfiguration.java    From camunda-spring-boot-amqp-microservice-cloud-example with Apache License 2.0 4 votes vote down vote up
@Bean
public Cloud cloud() {
  return new CloudFactory().getCloud();
}
 
Example #25
Source File: AbstractCloudConfig.java    From spring-cloud-connectors with Apache License 2.0 2 votes vote down vote up
/**
 * Get the cloud factory.
 *
 * Most applications will never need this method, but provided here to cover corner cases.
 *
 * @return cloud factory
 */
protected CloudFactory cloudFactory() {
	return cloudFactory;
}