SoftLayer API: ordering bandwidth pool - bandwidth

For N/W Part, when we tried to 'add' the new bandwidth pool, there was 25$ fee for the installation.
But I failed to find API to call that fee.
Even there'was no ID that required 25$ setup fee.
What do I have to use for adjusting that installation fee?
Please I want to know how to code,
'Adding Bandwidth Pool' in java.
Thanks.

Take a look the following Java Scripts:
1. To get the Bandwidhth Pool's fee for add Vdr Member/Installation:
package SoftLayer.api_java;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.account.Attribute;
import com.softlayer.api.service.Account;
/**
* This script retrieves a Vdr Member Price
*
* Important pages:
* http://sldn.softlayer.com/reference/services/SoftLayer_Account/getAttributeByType
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account_Attribute
*/
public class GetVdrMemberPrice {
public GetVdrMemberPrice() {
// Declare your SoftLayer username and apiKey
String user = "set me";
String apikey = "set me";
// Declare API Client
ApiClient client = new RestApiClient().withCredentials(user, apikey);
// Declare the type of account attribute you wish to retrieve
String attributeType = "VDR_MEMBER_PRICE";
try {
Attribute result = Account.service(client).getAttributeByType(attributeType);
System.out.println("Value: " + result.getValue());
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
public static void main(String[] args) {
new GetVdrMemberPrice();
}
}
2. To add Bandwidth Pool
package SoftLayer.api_java;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.network.bandwidth.version1.Allotment;
/**
* Add a Bandwidth Pool
*
* Important pages:
* http://sldn.softlayer.com/reference/services/SoftLayer_Network_Bandwidth_Version1_Allotment
* http://sldn.softlayer.com/reference/services/SoftLayer_Network_Bandwidth_Version1_Allotment/createObject
*/
public class AddingBandwidthPool {
public AddingBandwidthPool() {
// Declare your SoftLayer username and apiKey
String user = "set me";
String apikey = "set me";
// Define your account Id (set me)
Long accountId = new Long(123456);
// Define an identifier marking this allotment as a virtual private rack (1) or a bandwidth pooling(2).
Long bandwidthAllotmentTypeId = new Long(2);
// Define the region. You can get available regions using SoftLayer_Location_Group::getAllObjects method
// http://sldn.softlayer.com/reference/services/SoftLayer_Location_Group/getAllObjects
Long locationGroupId = new Long(1);
// Define text a virtual rack's name.
String name = "set me";
// Declare API Client
ApiClient client = new RestApiClient().withCredentials(user, apikey);
// Build a SoftLayer_Network_Bandwidth_Version1_Allotment object that you wish to create
Allotment templateObject = new Allotment();
templateObject.setAccountId(accountId);
templateObject.setBandwidthAllotmentTypeId(bandwidthAllotmentTypeId);
templateObject.setLocationGroupId(locationGroupId);;
templateObject.setName(name);
try {
boolean result = Allotment.service(client).createObject(templateObject);
System.out.println(result);
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
public static void main(String[] args) {
new AddingBandwidthPool();
}
}
Note: There is an issue with the return value for: SoftLayer_Network_Bandwidth_Version1_Allotment::createObject, because according to wsdl, it returns a boolean, but it is returning a SoftLayer_Network_Bandwidth_Version1_Allotment object. However, the bandwidth pool is added successfully.
References:
GetVdrMemberPrice
CreateBandwidthPool

Related

Message channels one or many?

I need to handle emails from about 30 addresses. I implement this in a way where all emails going to one DirectChannel and after to Receiver. In Receiver I can understand from what address is message comes, to do this I create CustomMessageSource that wraps javax.mail.Message to my own type that contains javax.mail.Message and some Enum. Looks like this is not a good decision, cause I can use #Transformer, but how can I use it if I have only 1 channel?
That was the first question.
Second question:
Should I use ONE channel and ONE receiver for all that addresses? Or better to have channel and receiver for each mail address? I don't understand Spring so deeply to feel the difference.
p.s. this question is continuation of Spring multiple imapAdapter
In each child context, you can add a header enricher to set a custom header to the URL from the adapter; with the output channel being the shared channel to the shared service.
In the service, use void foo(Message emailMessage, #Header("myHeader") String url)
I would generally recommend using a single service unless the service needs to do radically different things based on the source.
EDIT:
I modified my answer to your previous question to enhance the original message with the url in a header; each instance has its own header enricher and they all route the enriched message to the common emailChannel.
#Configuration
#EnableIntegration
public class GeneralImapAdapter {
#Value("${imap.url}")
String imapUrl;
#Bean
public static PropertySourcesPlaceholderConfigurer pspc() {
return new PropertySourcesPlaceholderConfigurer();
}
#Bean
#InboundChannelAdapter(value = "enrichHeadersChannel", poller = #Poller(fixedDelay = "10000") )
public MessageSource<javax.mail.Message> mailMessageSource(MailReceiver imapMailReceiver) {
return new MailReceivingMessageSource(imapMailReceiver);
}
#Bean
public MessageChannel enrichHeadersChannel() {
return new DirectChannel();
}
#Bean
#Transformer(inputChannel="enrichHeadersChannel", outputChannel="emailChannel")
public HeaderEnricher enrichHeaders() {
Map<String, ? extends HeaderValueMessageProcessor<?>> headersToAdd =
Collections.singletonMap("emailUrl", new StaticHeaderValueMessageProcessor<>(this.imapUrl));
HeaderEnricher enricher = new HeaderEnricher(headersToAdd);
return enricher;
}
#Bean
public MailReceiver imapMailReceiver() {
MailReceiver receiver = mock(MailReceiver.class);
Message message = mock(Message.class);
when(message.toString()).thenReturn("Message from " + this.imapUrl);
Message[] messages = new Message[] {message};
try {
when(receiver.receive()).thenReturn(messages);
}
catch (MessagingException e) {
e.printStackTrace();
}
return receiver;
}
}
...and I modified the receiving service so it gets access to the header...
#MessageEndpoint
public class EmailReceiverService {
#ServiceActivator(inputChannel="emailChannel")
public void handleMessage(Message message, #Header("emailUrl") String url) {
System.out.println(message + " header:" + url);
}
}
...hope that helps.
EDIT 2:
And this one's a bit more sophisticated; it pulls the from from the payload and puts it in a header; not needed for your use case since you have the full message, but it illustrates the technique...
#Bean
#Transformer(inputChannel="enrichHeadersChannel", outputChannel="emailChannel")
public HeaderEnricher enrichHeaders() {
Map<String, HeaderValueMessageProcessor<?>> headersToAdd = new HashMap<>();
headersToAdd.put("emailUrl", new StaticHeaderValueMessageProcessor<String>(this.imapUrl));
Expression expression = new SpelExpressionParser().parseExpression("payload.from[0].toString()");
headersToAdd.put("from", new ExpressionEvaluatingHeaderValueMessageProcessor<>(expression, String.class));
HeaderEnricher enricher = new HeaderEnricher(headersToAdd);
return enricher;
}
and
#ServiceActivator(inputChannel="emailChannel")
public void handleMessage(Message message, #Header("emailUrl") String url,
#Header("from") String from) {
System.out.println(message + " header:" + url + " from:" + from);
}

Only One Method Call is Shown in Output

I am trying to figure out how to call and output my methods correctly. However, in the output, only one method call is shown (the last one). How do I get it to output all of the method calls and not just the last one. Seems like all of the previous method calls are getting overridden and only the last one persists. I am just beginning in Java. Any help would be appreciated.
Here is the PartyDriver Class where I make 5 method calls. Only the last one is showing in the printParty method.
import java.util.ArrayList;
public class PartyDriver
{
public static void main(String[] args)
{
Party party = new Party(3, "David Beckham");
ArrayList<String> guest = new ArrayList<>();
party.addGuest("Roberto Baggio");
party.addGuest("Zinedine Zidane");
party.addGuest("Roberto Baggio");
party.addGuest("Johan Cruyff");
party.addGuest("Diego Maradona");
party.printParty();
} // end main
}//End Party Driver
Here is the Party Class with all of my methods:
import java.util.ArrayList;
public class Party
{
// instance variables that will hold your data
// private indicates they belong to this class exclusively
private int maxGuests;
private String host;
private String guest;
//Constructor
public Party(int maxGuests, String host)
{
this.maxGuests = maxGuests;
this.host = host;
}
//getter
// define type of data to be returned
public String getHost()
{
return host;
}
//setter
// setters have type void b/c they return nothing
public void setHost(String host)
{
this.host = host;
}
//*************************************
//Method to add to guest list
public void addGuest(String guest)
{
this.guest = guest;
}
//*************************************
//Method to print party
public void printParty()
{
System.out.println("Guest list for " +
this.host + "'s party is: \n\n" +
this.guest + ".\n");
} // end Print Party method
}//end class Party
No methods but PrintParty() print anything because you haven't told any methods but PrintParty() to print anything.
One way to print output to the console is to use System.out.println().
I've adjusted each of your methods to print something to the screen. I also added a guests instance variable to your Party class and made your addGuest(String guest) method modify that instance variable appropriately.
import java.util.ArrayList;
public class Party
{
// instance variables that will hold your data
// private indicates they belong to this class exclusively
private int maxGuests;
private String host;
private ArrayList<String> guests;
//Constructor
public Party(int maxGuests, String host)
{
System.out.println("Initializing party with maxGuests: '" + maxGuests + "' and host: '" + host + "'");
this.guests = new ArrayList<String>();
this.maxGuests = maxGuests;
this.host = host;
}
//getter
// define type of data to be returned
public String getHost()
{
System.out.println("Setting host to: " + host);
return host;
}
//setter
// setters have type void b/c they return nothing
public void setHost(String host)
{
System.out.println("Setting host to: " + host);
this.host = host;
}
//*************************************
//Method to add to guest list
public void addGuest(String guest)
{
if (guests.size() < maxGuests)
{
System.out.println("Adding guest: " + guest);
this.guests.add(guest);
}
else
{
System.out.println("Guest list full");
}
}
//*************************************
//Method to print party
public void printParty()
{
System.out.println("Guest list for " +
this.host + "'s party is: \n\n" +
this.guests + ".\n");
} // end Print Party method
public static void main(String[] args)
{
Party party = new Party(3, "David Beckham");
party.addGuest("Roberto Baggio");
party.addGuest("Zinedine Zidane");
party.addGuest("Roberto Baggio");
party.addGuest("Johan Cruyff");
party.addGuest("Diego Maradona");
party.printParty();
} // end main
}//end class Party

How to retrieve all the Groups/Roles a user is member of using SOAP services?

I am trying to collect some user informations using SOAP services.
I was able to get the Job Title for a given user, but I don't understand how to retrieve the list of groups and roles that a user has.
Can I simply use the GroupServiceSoap.getUserPlaces(long userId, String[] classNames, int max) method? Or is there another way I can get these fields?
Currently my code:
private static URL _getURL(String remoteUser, String password, String serviceName) {
final String LIFERAY_PROTOCOL = "http://";
final String LIFERAY_TCP_PORT = "8080";
final String LIFERAY_FQDN = "localhost";
final String LIFERAY_AXIS_PATH = "/api/secure/axis/";
try {
return new URL(LIFERAY_PROTOCOL + URLEncoder.encode(remoteUser, "UTF-8") + ":"
+ URLEncoder.encode(password, "UTF-8") + "#" + LIFERAY_FQDN
+ ":" + LIFERAY_TCP_PORT + LIFERAY_AXIS_PATH + serviceName);
} catch (MalformedURLException e) {
return null;
} catch (UnsupportedEncodingException e) {
return null;
}
}
[...]
public static void main(String[] argv){
public final String LIFERAY_USER_SERVICE="Portal_UserService";
public final String LIFERAY_COMPANY_SERVICE="Portal_CompanyService";
public final String LIFERAY_GROUP_SERVICE = "Portal_GroupService";
//company.default.web.id property
public final String LIFERAY_DEFAULT_COMPANY_ID = "liferay.com";
UserServiceSoap userService = new UserServiceSoapServiceLocator().getPortal_UserService(_getURL(USER_IDENTIFIER,USER_PASSWORD, LIFERAY_USER_SERVICE));
//This code is usefull if you want to use SOAP setter.
//((Portal_UserServiceSoapBindingStub) userService).setUsername(USER_IDENTIFIER);
//((Portal_UserServiceSoapBindingStub) userService).setPassword(USER_PASSWORD);
CompanyServiceSoap companyService = new CompanyServiceSoapServiceLocator().getPortal_CompanyService(_getURL(USER_IDENTIFIER, USER_PASSWORD, LIFERAY_COMPANY_SERVICE));
long companyId = companyService.getCompanyByMx(LIFERAY_DEFAULT_COMPANY_ID).getCompanyId();
// Here I retrieve my user, and can access some properties, but not them all !
UserSoap user = userService.getUserByEmailAddress(companyId, target_user_mail);
//TODO : I got hte JobTittle that I want, later I will do something more util thant just print it, I swear it my precious !
System.out.println(user.getJobTitle());
GroupServiceSoap groupService = new GroupServiceSoapServiceLocator().getPortal_GroupService(_getURL(USER_IDENTIFIER, USER_PASSWORD, LIFERAY_GROUP_SERVICE));
//this one return an empty array
GroupSoap[] userPlaces = groupService.getUserPlaces(new String[]{"Group", "Role"}, 150);
//this return an array of size 1, but the only GroupSoap seems to be a structural groups without any usefull properties to me.
GroupSoap[] userPlaces = groupService.getUserPlaces(null, 150);
}
Use this method to get user role and group user id
UserServiceSoap.getRoleUserIds
UserServiceSoap.getGroupUserIds
HTH
It is only a partial answer.
In order to get all the User Roles one can do this :
RoleServiceSoap roleService = new RoleServiceSoapServiceLocator().getPortal_RoleService(_getURL(USER_IDENTIFIER, USER_PASSWORD, LIFERAY_ROLE_SERVICE));
RoleSoap[] userRoles = roleService.getUserRoles(user.getUserId());
with user variable an instance of UserSoap.
The SOAP access must be done by an Admin user in order to get access to the Role List. The user can't access this himself.

GCS: 400 Bad Request retrieving bucket

Just getting started with GCS and its Java API. Adapted the Google Plus example and am trying to retrieve a bucket.
I get the error:
400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
"message" : "Invalid Value"
}
Here's my relevant code:
Main:
public static void main(String[] args)
{
try
{
try
{
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
// service account credential (uncomment setServiceAccountUser for domain-wide delegation)
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(StorageScopes.DEVSTORAGE_READ_WRITE)
.setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_NAME))
// .setServiceAccountUser("user#example.com")
.build();
// set up global Storage instance
storage = new Storage.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
// run commands
getBucket();
// success!
return;
} catch (IOException e)
{
System.err.println(e.getMessage());
}
} catch (Throwable t)
{
t.printStackTrace();
}
System.exit(1);
}
Get bucket method:
/** Get a BUCKET??? for which we already know the ID. */
private static void getBucket() throws IOException
{
View.header1("Retrieve a bucket by name.");
String bucketName = "gs://gsdogs";
Bucket bucket = storage.buckets().get(bucketName).execute();
View.show(bucket);
}
Constants:
private static final String CLIENT_ID = "************.apps.googleusercontent.com";
private static final String KEY_FILE_NAME = "privatekey.p12";
private static final String APPLICATION_NAME = "Elf-MobileCCtv/1.0";
/** E-mail address of the service account. */
private static final String SERVICE_ACCOUNT_EMAIL = "************#developer.gserviceaccount.com";
/** Global instance of the HTTP transport. */
private static HttpTransport HTTP_TRANSPORT;
/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
// We are using GCS not Google plus.
private static Storage storage;
Thanks in advance!
I had to change my bucket name from gs://gsdogs to gsdogs. Wow.

Value lost when transferring from server to client in silverlight

I am making a Silverlight app using WCF. I want to get the status of the hard-disks from remote servers and I am able to do that on the server side using a Management object. I have defined a wrapper class to hold the data of the hard-disks and store the objects in a list which I return.
Earlier, when the wrapper class was in the server project, it worked fine. However, when I transferred the class to a class library project in the same solution, the asynchronous call-completed event handler on the client side now gives me an event argument that is empty, i.e. an empty list
I tried debugging both the server and client code, and I see that the server creates the list properly and accesses the disk objects nicely. But the client code simply shows the list to be of size 0.
My client code is:
private void getDiskStatus()
{
diskSpaceStatus.Text = "Running...";
if (server == string.Empty)
{
server = "localhost";
}
diskServer.Text = server;
LogReaderClient proxy = new LogReaderClient();
proxy.getDiskSpaceCompleted += new EventHandler<getDiskSpaceCompletedEventArgs>(proxy_getDiskSpaceCompleted);
proxy.getDiskSpaceAsync(server);
}
void proxy_getDiskSpaceCompleted(object sender, getDiskSpaceCompletedEventArgs e)
{
diskSpaceStatus.Text = "Completed";
try
{
List<uDisk> udisks = new List<uDisk>();
foreach (Disk d in e.Result)
{
uDisk ud = new uDisk(d);
udisks.Add(ud);
}
diskTable.ItemsSource = udisks;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Where uDisk is another wrapper class for the client side.
My server code is:
[OperationContract]
public List<Disk> getDiskSpace(string server)
{
ConnectionOptions conn = new ConnectionOptions();
ManagementScope scope = new ManagementScope("\\\\" + server + "\\root\\cimv2", conn);
try
{
scope.Connect();
}
catch (Exception ex)
{
error = ex.Message;
}
ObjectQuery oq = new ObjectQuery("select FreeSpace, Size, Name from Win32_LogicalDisk where DriveType=3");
ManagementObjectSearcher search = new ManagementObjectSearcher(scope, oq);
ManagementObjectCollection moc = search.Get();
List<Disk> disks = new List<Disk>();
Disk d;
foreach (ManagementObject mo in moc)
{
d = new Disk(mo);
disks.Add(d);
}
return disks;
}
And the server wrapper class is:
namespace LogFilter.DataObjects
{
[DataContract]
public class Disk
{
[DataMember]
public string name;
[DataMember]
public double freeSpace;
[DataMember]
public double size;
[DataMember]
public double percentFree;
public Disk()
{}
public Disk(ManagementObject mo)
{
this.name = Convert.ToString(mo["Name"]);
this.freeSpace = Convert.ToDouble(mo["FreeSpace"]);
this.size = Convert.ToDouble(mo["Size"]);
this.percentFree = freeSpace * 100 / size;
}
}
}
The wrapper class is in the namespace LogFilter.DataObjects and the Server code is in the namespace LogFilter.Web.
Can anyone provide a solution to this?
Also can someone please give me a resource as to how to set the transfermode in a Silverlight application to Buffered?