List of usage examples for org.apache.commons.lang.builder ToStringStyle MULTI_LINE_STYLE
ToStringStyle MULTI_LINE_STYLE
To view the source code for org.apache.commons.lang.builder ToStringStyle MULTI_LINE_STYLE.
Click Source Link
From source file:com.gemini.provision.security.openstack.SecurityProviderOpenStackImpl.java
/** * * @param tenant//from w w w . java2s.co m * @param env * @param securityGroup - the security group to be created * @return SUCCESS, AUTH_FAILURE, CLOUD_FAILURE, OBJECT_EXISTS * * Creates the Security group in OpenStack if it doesn't exist NOTE: it * creates all security rules in the group. A separate call to create rules * IS NOT required */ @Override public ProvisioningProviderResponseType createSecurityGroup(GeminiTenant tenant, GeminiEnvironment env, GeminiSecurityGroup securityGroup) { //authenticate the session with the OpenStack installation OSClient os = OSFactory.builder().endpoint(env.getEndPoint()) .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName()) .authenticate(); if (os == null) { Logger.error("Failed to authenticate Tenant: {}", ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE)); return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE; } SecurityGroup osSecGrp = null; try { List<? extends SecurityGroup> osSecGrps = os.networking().securitygroup().list(); osSecGrp = osSecGrps.stream().filter(osg -> osg.getName().equals(securityGroup.getName())).findFirst() .get(); } catch (NullPointerException | ClientResponseException ex) { Logger.error( "Cloud Exception: {}\nCould not retrieve security group information in OpenStack. tenant: {} env: {} security group: {}", ex.toString(), tenant.getName(), env.getName(), securityGroup.getName()); return ProvisioningProviderResponseType.CLOUD_EXCEPTION; } catch (NoSuchElementException ex) { //security group not found, so ok to move forward with the creation } if (osSecGrp != null) { Logger.error("Security Group exists: tenant: {} env: {} security group: {}", tenant.getName(), env.getName(), securityGroup.getName()); return ProvisioningProviderResponseType.OBJECT_EXISTS; } //create the security group osSecGrp = os.networking().securitygroup().create(Builders.securityGroup().tenantId(tenant.getTenantID()) .name(securityGroup.getName()).description(securityGroup.getDescription()).build()); if (osSecGrp == null) { Logger.error("Security Group creation failure tenant: {} env: {} security group: {}", tenant.getName(), env.getName(), securityGroup.getName()); return ProvisioningProviderResponseType.CLOUD_FAILURE; } //map the object and then create the security group rules in the cloud securityGroup.setCloudID(osSecGrp.getId()); securityGroup.setProvisioned(true); securityGroup.getSecurityRules().stream().forEach(s -> { SecurityGroupRule r = null; try { r = os.networking().securityrule() .create(Builders.securityGroupRule().tenantId(tenant.getTenantID()) .securityGroupId(securityGroup.getCloudID()) .direction(s.getDirection().toString().toLowerCase()) .ethertype(s.getIpAddressType().toString()).portRangeMin(s.getPortRangeMin()) .portRangeMax(s.getPortRangeMax()).protocol(s.getProtocol().toString()) // .remoteGroupId(s.getRemoteGroupId()) .remoteIpPrefix(s.getRemoteIpPrefix()).build()); //copy the id s.setCloudID(r.getId()); s.setProvisioned(true); } catch (ClientResponseException | NullPointerException ex) { Logger.error( "Cloud Exception {} - Security Group rule creation failure tenant: {} env: {} security group: {} rule: {}", ex.toString(), tenant.getName(), env.getName(), securityGroup.getName(), s.getName()); } }); Logger.debug("Successfully created security group Tenant: {} Env: {} security group {}", tenant.getName(), env.getName(), securityGroup.getName()); return ProvisioningProviderResponseType.SUCCESS; }
From source file:com.likethecolor.alchemy.api.entity.AlchemyObjectTest.java
@Test public void testToString_Formatted() { final ToStringStyle style = ToStringStyle.MULTI_LINE_STYLE; final String text = "Israel"; final String census = "http://census.org/resource/Israel"; final String ciaFactbook = "http://www4.wiwiss.fu-berlin.de/factbook/resource/Israel"; final String crunchbase = "http://crunchbase.com/resource/Israel"; final String dbPedia = "http://dbpedia.org/resource/Israel"; final String freebase = "http://rdf.freebase.com/ns/guid.9202a8c04000641f800000000001e2be"; final Double latitude = 31.0D; final Double longitude = 35.0D; final String geo = latitude + " " + longitude; final String geonames = "http://geonames.com/Israel"; final String musicBrainz = "http://musicbrainz.com/Israel"; final String name = "Israel"; final String opencyc = "http://sw.opencyc.org/concept/Mx4rvViP55wpEbGdrcN5Y29ycA"; final String semanticCrunchbase = "http://semanticcrunchbase.com/concept/Mx4rvViP55wpEbGdrcN5Y29ycA"; final String type = "Country"; final String entityText = "Israel"; final String umbel = "http://umbel.org/umbel/ne/wikipedia/Israel"; final String website = "http://www.knesset.gov.il/"; final String yago = "http://mpii.de/yago/resource/Israel"; final List<String> subtypes = new ArrayList<String>(); subtypes.add("Location"); subtypes.add("Country"); subtypes.add("GovernmentalJurisdiction"); final AlchemyEntity entityAlchemyEntity = new AlchemyEntity(); entityAlchemyEntity.setCensus(census); entityAlchemyEntity.setCIAFactbook(ciaFactbook); entityAlchemyEntity.setCrunchbase(crunchbase); entityAlchemyEntity.setDBPedia(dbPedia); entityAlchemyEntity.setFreebase(freebase); entityAlchemyEntity.setGeo(geo);//from w w w .j ava2 s . c o m entityAlchemyEntity.setGeonames(geonames); entityAlchemyEntity.setMusicBrainz(musicBrainz); entityAlchemyEntity.setName(name); entityAlchemyEntity.setOpencyc(opencyc); entityAlchemyEntity.setSemanticCrunchbase(semanticCrunchbase); entityAlchemyEntity.setText(entityText); entityAlchemyEntity.setType(type); entityAlchemyEntity.setUmbel(umbel); entityAlchemyEntity.setWebsite(website); entityAlchemyEntity.setYago(yago); for (String subtype : subtypes) { entityAlchemyEntity.addSubtype(subtype); } final boolean isMixed = true; final Double sentimentScore = 0.9734D; final SentimentAlchemyEntity.TYPE sentimentType = SentimentAlchemyEntity.TYPE.POSITIVE; final SentimentAlchemyEntity sentimentEntity = new SentimentAlchemyEntity(isMixed, sentimentScore, sentimentType.toString()); final boolean isMixedFromSubject = true; final Double sentimentScoreFromSubject = 0.9734D; final SentimentAlchemyEntity.TYPE sentimentTypeFromSubject = SentimentAlchemyEntity.TYPE.POSITIVE; final SentimentAlchemyEntity sentimentEntityFromSubject = new SentimentAlchemyEntity(isMixedFromSubject, sentimentScoreFromSubject, sentimentTypeFromSubject.toString()); final AlchemyObject object = new AlchemyObject(); object.setEntity(entityAlchemyEntity); object.setSentiment(sentimentEntity); object.setSentimentFromSubject(sentimentEntityFromSubject); object.setText(text); final String expectedString = new ToStringBuilder(object, style) .append("entity", entityAlchemyEntity.toString(style)) .append("sentiment", sentimentEntity.toString(style)) .append("sentiment from subject", sentimentEntityFromSubject.toString(style)).append("text", text) .toString(); final String actualString = object.toString(style); assertEquals(expectedString, actualString); }
From source file:com.xtructure.xneat.genetics.GeneMap.java
@Override public String toString() { ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE); for (Gene g : getNodes()) { tsb.append(g);//www. j av a 2 s .com } for (Gene g : getLinks()) { tsb.append(g); } return tsb.toString(); }
From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java
/** * getAllSubnets. Lists all the subnets in the cloud - function may not have * practical use in OpenStack. Use getSubnets and provide a network to get * subnets specific to a network./* w w w.ja v a 2 s . c o m*/ * * @param tenant - the tenant * @param env - the environment with the subnets * @return */ @Override public List<GeminiSubnet> getAllSubnets(GeminiTenant tenant, GeminiEnvironment env) { //authenticate the session with the OpenStack installation OSClient os = OSFactory.builder().endpoint(env.getEndPoint()) .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName()) .authenticate(); if (os == null) { Logger.error("Failed to authenticate Tenant: {}", ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE)); return null; } //get all the subnets List<? extends Subnet> subnets = os.networking().subnet().list(); if (subnets.isEmpty()) { return null; } List<GeminiSubnet> gemSubnets = new ArrayList(); //map the list of network gateways and their subnets to gemini equivalents subnets.stream().forEach(s -> { GeminiSubnet gn = new GeminiSubnet(); //the basic elements gn.setName(s.getName()); gn.setCloudID(s.getId()); gn.setCidr(s.getCidr()); gn.setGateway(InetAddresses.forString(s.getGateway())); //connect with the parent network try { //match the parent network to one in the application gn.setParent( env.getApplications().stream().map(GeminiApplication::getNetworks).flatMap(List::stream) .filter(g -> g.getCloudID().equals(s.getNetworkId())).findAny().get()); } catch (NoSuchElementException | NullPointerException ex) { try { //could not find a parent network in the applications, now look in the orphaned networks gn.setParent(env.getOrphanNetworks().stream() .filter(g -> g.getCloudID().equals(s.getNetworkId())).findAny().get()); } catch (NoSuchElementException | NullPointerException e) { gn.setParent(null); //VERY BAD SITUATION - GEMINI MODEL IS COMPLETELY OUT OF SYNC Logger.error( "Subnet {} has a network that isn't in Applications or orphaned networks. subnet {} parent network {}", gn.getName(), s.getNetworkId()); } } gn.setEnableDHCP(s.isDHCPEnabled()); gn.setNetworkType(s.getIpVersion() == IPVersionType.V6 ? IPAddressType.IPv6 : IPAddressType.IPv4); s.getHostRoutes(); s.getAllocationPools().stream().forEach(ap -> { GeminiSubnetAllocationPool gsap = new GeminiSubnetAllocationPool( InetAddresses.forString(ap.getStart()), InetAddresses.forString(ap.getEnd())); gn.addAllocationPool(gsap); }); gemSubnets.add(gn); }); return gemSubnets; }
From source file:com.likethecolor.alchemy.api.entity.LanguageAlchemyEntityTest.java
@Test public void testToString_Formatted() { final ToStringStyle style = ToStringStyle.MULTI_LINE_STYLE; final String language = "english"; final String ethnologue = "http://www.ethnologue.com/show_language.asp?code=eng"; final String iso6391 = "eng"; final String iso6392 = "eng"; final String iso6393 = "eng"; final String numberOfNativeSpeakers = "1.322307-6.021120 million"; final String wikipedia = "http://en.wikipedia.org/wiki/English_language"; final LanguageAlchemyEntity entity = new LanguageAlchemyEntity(language); entity.setEthnologue(ethnologue);//from w w w. java 2s. c om entity.setIso6391(iso6391); entity.setIso6392(iso6392); entity.setIso6393(iso6393); entity.setNumberOfNativeSpeakers(numberOfNativeSpeakers); entity.setWikipedia(wikipedia); final String expectedString = new ToStringBuilder(entity, style).append("ethnologue", ethnologue) .append("iso-639-1", iso6391).append("iso-639-2", iso6392).append("iso-639-3", iso6393) .append("number of native speakers", numberOfNativeSpeakers).append("wikipedia", wikipedia) .toString(); final String actualString = entity.toString(style); assertEquals(expectedString, actualString); }
From source file:com.gemini.provision.security.openstack.SecurityProviderOpenStackImpl.java
@Override public ProvisioningProviderResponseType updateSecurityGroup(GeminiTenant tenant, GeminiEnvironment env, GeminiSecurityGroup securityGroup) { //authenticate the session with the OpenStack installation OSClient os = OSFactory.builder().endpoint(env.getEndPoint()) .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName()) .authenticate();//from w w w.ja va 2 s. co m if (os == null) { Logger.error("Failed to authenticate Tenant: {}", ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE)); return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE; } SecurityGroup osSecGrp; try { osSecGrp = os.networking().securitygroup().get(securityGroup.getCloudID()); } catch (NullPointerException | ClientResponseException ex) { Logger.error( "Could not retrieve security group information in OpenStack. tenant: {} env: {} security group: {}", tenant.getName(), env.getName(), securityGroup.getName()); return ProvisioningProviderResponseType.CLOUD_EXCEPTION; } if (osSecGrp == null) { Logger.error("Security Group does not exist: tenant: {} env: {} security group: {}", tenant.getName(), env.getName(), securityGroup.getName()); return ProvisioningProviderResponseType.OBJECT_NOT_FOUND; } //looks like there no way to update a security group, we have to delete and re-create ActionResponse a = os.networking().securitygroup().delete(osSecGrp.getId()); if (!a.isSuccess()) { Logger.error( "Security Group update - could not delete the security group: tenant: {} env: {} security group: {} Error Message: {}", tenant.getName(), env.getName(), securityGroup.getName(), a.getFault()); return ProvisioningProviderResponseType.CLOUD_FAILURE; } //now re-create the group with the updated info //create the security group osSecGrp = os.networking().securitygroup().create(Builders.securityGroup().tenantId(tenant.getTenantID()) .name(securityGroup.getName()).description(securityGroup.getDescription()).build()); if (osSecGrp == null) { Logger.error("Security Group update, creation failure. tenant: {} env: {} security group: {}", tenant.getName(), env.getName(), securityGroup.getName()); return ProvisioningProviderResponseType.CLOUD_FAILURE; } //update the cloud ID since it has most likely changed and then create the security group rules in the cloud securityGroup.setCloudID(osSecGrp.getId()); securityGroup.setProvisioned(true); securityGroup.getSecurityRules().stream().forEach(s -> { SecurityGroupRule r = os.networking().securityrule() .create(Builders.securityGroupRule().tenantId(tenant.getTenantID()) .securityGroupId(securityGroup.getCloudID()) .direction(s.getDirection().toString().toLowerCase()) .ethertype(s.getIpAddressType().toString()).portRangeMin(s.getPortRangeMin()) .portRangeMax(s.getPortRangeMax()).protocol(s.getProtocol().toString()) // .remoteGroupId(s.getRemoteGroupId()) .remoteIpPrefix(s.getRemoteIpPrefix()).build()); if (r == null) { Logger.error("Security Group rule creation failure. tenant: {} env: {} security group: {} rule {}", tenant.getName(), env.getName(), securityGroup.getName(), s.getName()); } }); Logger.debug("Successfully updated security group Tenant: {} Env: {} security group {}", tenant.getName(), env.getName(), securityGroup.getName()); return ProvisioningProviderResponseType.SUCCESS; }
From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java
/** * getSubnets. Find all subnets related to a parent network. For each subnet * found it create an equivalent gemini object and adds it to the parent * network/*from w w w. j a va 2 s. co m*/ * * @param tenant - contains the environment, provides the auth parameters * @param env - contains the parent network whose subnets needs to be * retrieved * @param parent - the parent network whose subnets need to be retrieved * @return List<GeminiSubnet> list of the subnets found or null if there was * an error */ @Override public List<GeminiSubnet> getSubnets(GeminiTenant tenant, GeminiEnvironment env, GeminiNetwork parent) { //authenticate the session with the OpenStack installation OSClient os = OSFactory.builder().endpoint(env.getEndPoint()) .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName()) .authenticate(); if (os == null) { Logger.error("Failed to authenticate Tenant: {}", ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE)); return null; } //get all the subnets List<? extends Subnet> subnets = os.networking().subnet().list(); if (subnets == null || subnets.isEmpty()) { Logger.info("No subnets for tenant: {} env: {} network {}", tenant.getName(), env.getName(), parent.getName()); return null; } List<GeminiSubnet> gemSubnets = new ArrayList(); //map the list of network gateways and their subnets to gemini equivalents subnets.stream().filter(s -> s != null).filter(s -> s.getNetworkId().equals(parent.getCloudID())) .forEach(s -> { GeminiSubnet gn = new GeminiSubnet(); gn.setName(s.getName()); gn.setCloudID(s.getId()); gn.setCidr(s.getCidr()); gn.setGateway(InetAddresses.forString(s.getGateway())); gn.setParent(parent); gn.setEnableDHCP(s.isDHCPEnabled()); gn.setNetworkType( s.getIpVersion() == IPVersionType.V4 ? IPAddressType.IPv4 : IPAddressType.IPv6); s.getAllocationPools().stream().forEach(ap -> { GeminiSubnetAllocationPool gsap = new GeminiSubnetAllocationPool( InetAddresses.forString(ap.getStart()), InetAddresses.forString(ap.getEnd())); gn.addAllocationPool(gsap); }); gemSubnets.add(gn); gn.setParent(parent); parent.addSubnet(gn); }); return gemSubnets; }
From source file:com.xtructure.xevolution.genetics.impl.AbstractPopulation.java
@Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)// .append("id", getId())// .append("size", size())// .append("attributes", getAttributes())// .append("highGenomes", mapToString(highestGenomes))// .append("lowGenomes", mapToString(lowestGenomes))// .append("averageMeasures", mapToString(averageAttributes))// .toString();//from ww w . j av a 2 s . c o m }
From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java
@Override public ProvisioningProviderResponseType createSubnet(GeminiTenant tenant, GeminiEnvironment env, GeminiNetwork parent, GeminiSubnet newSubnet) { //authenticate the session with the OpenStack installation OSClient os = OSFactory.builder().endpoint(env.getEndPoint()) .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName()) .authenticate();/* ww w.ja v a 2 s . c o m*/ if (os == null) { Logger.error("Failed to authenticate Tenant: {}", ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE)); return null; } //check to see if the parenet network exists Network osParent; try { osParent = os.networking().network().list().stream() .filter(osn -> osn.getName().equals(parent.getName())).findFirst().get(); parent.setCloudID(osParent.getId()); //just in case... } catch (NoSuchElementException ex) { Logger.error( "Failed to create subnet - parent network does not exist. Tenant: {} Environment: {} network: {} subnet: {}", tenant.getName(), env.getName(), parent.getName(), newSubnet.getName()); return ProvisioningProviderResponseType.CLOUD_NO_PARENT; } //check to see if this subnet exists if (os.networking().subnet().list().stream().anyMatch(n -> n.getName().equals(newSubnet.getName()))) { Logger.error( "Failed to create subnet - already exists. Tenant: {} Environment: {} network: {} subnet: {}", tenant.getName(), env.getName(), parent.getName(), newSubnet.getName()); return ProvisioningProviderResponseType.OBJECT_EXISTS; } //create the subnet Subnet subnet; try { subnet = os.networking().subnet().create(Builders.subnet().tenantId(tenant.getTenantID()) .gateway(InetAddresses.toAddrString(newSubnet.getGateway())) .enableDHCP(newSubnet.isEnableDHCP()) .ipVersion( newSubnet.getNetworkType() == IPAddressType.IPv6 ? IPVersionType.V6 : IPVersionType.V4) .name(newSubnet.getName()).networkId(parent.getCloudID()).cidr(newSubnet.getCidr()).build()); } catch (ClientResponseException ex) { Logger.error( "Cloud exception: failed to create subnet. status code {} tenant: {} env: {} parent network: {} subnet {} ", ex.getStatusCode(), tenant.getName(), env.getName(), parent.getName(), newSubnet.getName()); return ProvisioningProviderResponseType.CLOUD_EXCEPTION; } //add the list of subnets (this will be an update the subnet just created) List<GeminiSubnetAllocationPool> pools = newSubnet.getAllocationPools(); pools.stream().forEach(p -> { if (os.networking().subnet().update(subnet.toBuilder() .addPool(p.getStart().getHostAddress(), p.getEnd().getHostAddress()).build()) == null) { Logger.error( "Failed to create subnet allocation pool, Tenant: {} Environment: {} Parent Network: {} Subnet: {} Allocation Pool {} {}", tenant.getName(), env.getName(), parent.getName(), newSubnet.getName(), p.getStart().getHostAddress(), p.getEnd().getHostAddress()); } }); //copy the id to the domain object newSubnet.setCloudID(subnet.getId()); Logger.debug("Successfully added network - tenant: {} env: {} parent network: {} subnet {} ", tenant.getName(), env.getName(), parent.getName(), newSubnet.getName()); return ProvisioningProviderResponseType.SUCCESS; }
From source file:com.xtructure.xevolution.genetics.impl.UTestAbstractPopulation.java
@SuppressWarnings("unchecked") public void toStringReturnsExpectedString() { DummyPopulation pop = new DummyPopulation(1); Genome<String> genome0 = new DummyGenome(RandomUtil.nextInteger(100), "data"); Genome<String> genome1 = new DummyGenome(RandomUtil.nextInteger(100) + 100, "data"); genome1.setFitness(1.0);//ww w . j a v a2s. c om genome1.incrementEvaluationCount(); genome1.incrementAge(); Genome<String> genome2 = new DummyGenome(RandomUtil.nextInteger(100) + 200, "data"); genome2.setFitness(2.0); genome2.incrementEvaluationCount(); genome2.incrementEvaluationCount(); genome2.incrementAge(); genome2.incrementAge(); pop.addAll(Arrays.asList(genome0, genome1, genome2)); pop.incrementAge(); pop.refreshStats(); ValueMap attributes = new ValueMap(); attributes.setAll(pop.getAttributes()); Map<XValId<?>, Genome<?>> highest = new HashMap<XValId<?>, Genome<?>>(); Map<XValId<?>, Genome<?>> lowest = new HashMap<XValId<?>, Genome<?>>(); Map<XValId<?>, Double> averages = new HashMap<XValId<?>, Double>(); highest.put(Genome.FITNESS_ATTRIBUTE_ID, genome2); highest.put(Genome.EVAL_COUNT_ATTRIBUTE_ID, genome2); highest.put(Genome.AGE_ATTRIBUTE_ID, genome2); lowest.put(Genome.FITNESS_ATTRIBUTE_ID, genome0); lowest.put(Genome.EVAL_COUNT_ATTRIBUTE_ID, genome0); lowest.put(Genome.AGE_ATTRIBUTE_ID, genome0); averages.put(Genome.FITNESS_ATTRIBUTE_ID, 1.0); averages.put(Genome.EVAL_COUNT_ATTRIBUTE_ID, 1.0); averages.put(Genome.AGE_ATTRIBUTE_ID, 2.0); String expected = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)// .append("id", AbstractPopulation.POPULATION_BASE_ID.createChild(1))// .append("size", 3)// .append("attributes", attributes)// .append("highGenomes", mapToString(highest))// .append("lowGenomes", mapToString(lowest))// .append("averageMeasures", mapToString(averages))// .toString(); expected = expected.substring(expected.indexOf('\n')); String popString = pop.toString(); popString = popString.substring(popString.indexOf('\n')); assertThat("", // popString, isEqualTo(expected)); }