Java Code Examples for org.springframework.cloud.Cloud#getServiceInfos()

The following examples show how to use org.springframework.cloud.Cloud#getServiceInfos() . 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: SolaceJmsAutoCloudConfiguration.java    From solace-jms-spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the first detected {@link SolaceMessagingInfo}.
 *
 * @deprecated As of 1.1.0, usage of {@link SolaceMessagingInfo}
 * was replaced by its interface, {@link SolaceServiceCredentials}.
 * Use {@link #findFirstSolaceServiceCredentials()} instead.
 *
 * @return If in a Cloud Foundry environment, a Solace PubSub+ service is returned, otherwise null
 */
@Deprecated
@Bean @Primary
public SolaceMessagingInfo findFirstSolaceMessagingInfo() {
	SolaceMessagingInfo solacemessaging = null;
	Cloud cloud = cloudFactory.getCloud();
	List<ServiceInfo> serviceInfos = cloud.getServiceInfos();
	for (ServiceInfo serviceInfo : serviceInfos) {
		// Stop when we find the first one...
		// TODO: Consider annotation driven selection, or sorted plan based
		// selection
		if (serviceInfo instanceof SolaceMessagingInfo) {
			solacemessaging = (SolaceMessagingInfo) serviceInfo;
			logger.info("Found Cloud Solace PubSub+ Service Instance Id: " + solacemessaging.getId());
			break;
		}
	}

	if (solacemessaging == null) {
		// The CloudCondition should shield from this happening, should not
		// arrive to this state.
		logger.error("Cloud Solace PubSub+ Info was not found, cannot auto-configure");
		throw new IllegalStateException(
				"Unable to create SolConnectionFactory did not find SolaceMessagingInfo in the current cloud environment");
	}

	return solacemessaging;
}
 
Example 2
Source File: SolaceJmsAutoCloudConfiguration.java    From solace-jms-spring-boot with Apache License 2.0 5 votes vote down vote up
@Deprecated
@Override
public List<SolaceMessagingInfo> getSolaceMessagingInfos() {
	List<SolaceMessagingInfo> solaceMessagingInfoList = new ArrayList<>();
	Cloud cloud = cloudFactory.getCloud();

	List<ServiceInfo> serviceInfos = cloud.getServiceInfos();
	for (ServiceInfo serviceInfo : serviceInfos) {
		if (serviceInfo instanceof SolaceMessagingInfo) {
			solaceMessagingInfoList.add((SolaceMessagingInfo) serviceInfo);
		}
	}
	return solaceMessagingInfoList;
}
 
Example 3
Source File: SolaceJavaAutoCloudConfiguration.java    From solace-java-spring-boot with Apache License 2.0 5 votes vote down vote up
@Deprecated
@Override
public List<SolaceMessagingInfo> getSolaceMessagingInfos() {
	List<SolaceMessagingInfo> solaceMessagingInfoList = new ArrayList<>();

	Cloud cloud = cloudFactory.getCloud();

	List<ServiceInfo> serviceInfos = cloud.getServiceInfos();
	for (ServiceInfo serviceInfo : serviceInfos) {
		if (serviceInfo instanceof SolaceMessagingInfo) {
			solaceMessagingInfoList.add((SolaceMessagingInfo) serviceInfo);
		}
	}
	return solaceMessagingInfoList;
}
 
Example 4
Source File: SolaceJavaAutoCloudConfiguration.java    From solace-java-spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the first detected {@link SolaceMessagingInfo}.
 *
 * @deprecated As of 1.1.0, usage of {@link SolaceMessagingInfo}
 * was replaced by its interface, {@link SolaceServiceCredentials}.
 * Use {@link SolaceJavaAutoConfigurationBase#findFirstSolaceServiceCredentials()} instead.
 *
 * @return If in a Cloud Foundry environment, a Solace PubSub+ service is returned, otherwise null
 */
@Deprecated
@Bean @Primary
public SolaceMessagingInfo findFirstSolaceMessagingInfo() {
	SolaceMessagingInfo solacemessaging = null;
	Cloud cloud = cloudFactory.getCloud();
	List<ServiceInfo> serviceInfos = cloud.getServiceInfos();
	for (ServiceInfo serviceInfo : serviceInfos) {
		// Stop when we find the first one...
		// TODO: Consider annotation driven selection, or sorted plan based
		// selection
		if (serviceInfo instanceof SolaceMessagingInfo) {
			solacemessaging = (SolaceMessagingInfo) serviceInfo;
			logger.info("Found Cloud Solace PubSub+ Service Instance Id: " + solacemessaging.getId());
			break;
		}
	}

	if (solacemessaging == null) {
		// The CloudCondition should shield from this happening, should not
		// arrive to this state.
		logger.error("Cloud Solace PubSub+ Info was not found, cannot auto-configure");
		throw new IllegalStateException(
				"Unable to create SpringJCSMPFactory did not find SolaceMessagingInfo in the current cloud environment");
	}

	return solacemessaging;
}
 
Example 5
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String[] getCloudProfiles(Cloud cloud) {
    if (cloud == null) {
        return null;
    }

    List<String> profiles = new ArrayList<>();

    List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

    LOGGER.info("Found serviceInfos: " + StringUtils.collectionToCommaDelimitedString(serviceInfos));

    for (ServiceInfo serviceInfo : serviceInfos) {
        if (serviceTypeToProfileName.containsKey(serviceInfo.getClass())) {
            profiles.add(serviceTypeToProfileName.get(serviceInfo.getClass()));
        }
    }

    if (profiles.size() > 1) {
        throw new IllegalStateException(
                "Only one service of the following types may be bound to this application: " +
                        serviceTypeToProfileName.values().toString() + ". " +
                        "These services are bound to the application: [" +
                        StringUtils.collectionToCommaDelimitedString(profiles) + "]");
    }

    if (profiles.size() > 0) {
        return createProfileNames(profiles.get(0), "cloud");
    }

    return null;
}
 
Example 6
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String[] getCloudProfiles(Cloud cloud) {
    if (cloud == null) {
        return null;
    }

    List<String> profiles = new ArrayList<>();

    List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

    LOGGER.info("Found serviceInfos: " + StringUtils.collectionToCommaDelimitedString(serviceInfos));

    for (ServiceInfo serviceInfo : serviceInfos) {
        if (serviceTypeToProfileName.containsKey(serviceInfo.getClass())) {
            profiles.add(serviceTypeToProfileName.get(serviceInfo.getClass()));
        }
    }

    if (profiles.size() > 1) {
        throw new IllegalStateException(
                "Only one service of the following types may be bound to this application: " +
                        serviceTypeToProfileName.values().toString() + ". " +
                        "These services are bound to the application: [" +
                        StringUtils.collectionToCommaDelimitedString(profiles) + "]");
    }

    if (profiles.size() > 0) {
        return createProfileNames(profiles.get(0), "cloud");
    }

    return null;
}
 
Example 7
Source File: TestRestController.java    From bluemix-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@GetMapping("/infos")
public String getInfos() {
  Cloud cloud = getCloud();
  List<ServiceInfo> infos = cloud.getServiceInfos();
  String result = "Info:\n";
  for (ServiceInfo info : infos) {
    result += info.getClass().toString() + "\n";
  }
  return result;
}
 
Example 8
Source File: SpringApplicationContextInitializer.java    From spring-music with Apache License 2.0 5 votes vote down vote up
public String[] getCloudProfile(Cloud cloud) {
    if (cloud == null) {
        return null;
    }

    List<String> profiles = new ArrayList<>();

    List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

    logger.info("Found serviceInfos: " + StringUtils.collectionToCommaDelimitedString(serviceInfos));

    for (ServiceInfo serviceInfo : serviceInfos) {
        if (serviceTypeToProfileName.containsKey(serviceInfo.getClass())) {
            profiles.add(serviceTypeToProfileName.get(serviceInfo.getClass()));
        }
    }

    if (profiles.size() > 1) {
        throw new IllegalStateException(
                "Only one service of the following types may be bound to this application: " +
                        serviceTypeToProfileName.values().toString() + ". " +
                        "These services are bound to the application: [" +
                        StringUtils.collectionToCommaDelimitedString(profiles) + "]");
    }

    if (profiles.size() > 0) {
        return createProfileNames(profiles.get(0), "cloud");
    }

    return null;
}