I need to create deployment with role that contains Chef extension via Java Azure SDK. I have next code for setting extension parameters, but it doesn't work.
As an example I use next material in Python http://blogs.msdn.com/b/shwetasblogs/archive/2015/02/19/creating-deployment-amp-customizing-linux-vms-with-python-amp-chef-part-2.aspx
private void withExtension(Role role) {
ArrayList<ResourceExtensionReference> references = new ArrayList<ResourceExtensionReference>();
ResourceExtensionReference reference = new ResourceExtensionReference();
reference.setReferenceName("LinuxChefClient");
reference.setVersion("11.*");
reference.setPublisher("Chef.Bootstrap.WindowsAzure");
reference.setName("LinuxChefClient");
ResourceExtensionParameterValue publicConfig = new ResourceExtensionParameterValue();
publicConfig.setType("Public");
publicConfig.setKey("PublicParams");
String value = "{\n" +
" \"client_rb\": \"chef_server_url \\\"https://<chefServerUri>\\\"\\nnode_name \\\"<vmName>\\\"\\nvalidation_key \\\"/etc/chef/validation.pem\\\"\\nlog_location \\\"/etc/chef/client.log\\\"\\nlog_level :info\\njson_attribs \\\"/etc/chef/role.json\\\"\",\n" +
" \"run_list\": [\"role[base]\"]\n" +
"}";
publicConfig.setValue(value);
ResourceExtensionParameterValue privateConfig = new ResourceExtensionParameterValue();
privateConfig.setType("Private");
privateConfig.setKey("PrivateParams");
privateConfig.setValue("{ \"validation_key\": \"" + VALIDATION_PEM + "\" }");
ArrayList<ResourceExtensionParameterValue> parameterValues = new ArrayList<ResourceExtensionParameterValue>();
parameterValues.add(publicConfig);
parameterValues.add(privateConfig);
reference.setResourceExtensionParameterValues(parameterValues);
references.add(reference);
role.setResourceExtensionReferences(references);
}
It seems that you do not encrypt the value of privateConfig and publicConfig. As this official document description(Request body part), before setting value, we need encrypt those values:
<PublicConfiguration>
base-64-encoded-xsd-for-extension-public-configuration
</PublicConfiguration>
<PrivateConfiguration>
base-64-encoded-xsd-for-extension-private-configuration
</PrivateConfiguration>
Please try to add this code into your project:
value=Base64.encode(value.getBytes(Charset.forName("UTF-8")));
By the way, please share more error information if the above code don't work.
I am not able to add the comment, so asking my questions in Reply -
What is the error that you see?
Is your VM getting created successfully?
George, please answer these questions so that I can help you better. By the way, you can check the blog - http://blogs.msdn.com/b/azureossds/archive/2015/09/08/accessing-vm-extensions-like-chef-using-azure-sdk-for-java-programmatically.aspx
for using Azure sdk for Java to access the extensions. You will have to modify the code to set the extension reference in order to create a new one.
Hope this helps !!
Related
I am using Jest client libraries to connect and interface with my ES cluster. I was able to injest documents to an index sucessfully and specify settings.
Settings.Builder settings = Settings.settingsBuilder();
settings.put("number_of_shards", 5);
settings.put("number_of_replicas", 1);
I am having issues with updating the settings that I have specified after indexing documents. The documentation doesn't seem to be clear on how to achieve this.
After an extensive google search, I found a solution. This can be achieved using the updatesettings class.
String body = "{ \"index\" : { " +
"\"number_of_replicas\" :50" + ","+
"} }";
UpdateSettings updateSettings = new UpdateSettings.Builder(body).addIndex(index).build();
I am working on a Java project where I am integrating Evernote services. Right now, I am able to save, update notes, but what I would like to do is to search notes. Now, As evernote is tied to our infrastructure, I would like to save an ID of the object whose text we are copying to Evernote.
So, whenever the text is updated, I would like to get the same Note from Evernote and update it's contents.
These are the two problems I am facing :
Saving our Primary key ID in Note object. Tried it with GUID, it gets saved as I can see the note in Sandbox, but have no idea how to search notes with GUID. If GUID shouldn't be the way, then where to save the primary key which is searchable.
As mentioned in first point, which attribute or variable should be set which can be searchable.
Here is some of the saving and searching code I have so far :
Note note = new Note();
note.setTitle("New title");
String nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">";
nBody += "<en-note>" + "Test" + "</en-note>";
note.setContent(nBody);
note.setGuid("1234");
Note savedNote = noteStoreClient.createNote(note);
Search code :
NoteFilter noteFilter = new NoteFilter();
// AS you can see, I have no idea what filter to set here.
// noteFilter.getTagGuids(id);
NoteList noteList = noteStoreClient.findNotes(noteFilter,0,100);
List<Note> notes = noteList.getNotes();
for(Note note : notes){
System.out.println("Note title is "+note.getTitle());
}
Kindly let me know what I can do. Thanks a lot. :-)
Udpate
This happens when I try to save the GUID with my own randomly created one.
Error log :
EDAMUserException(errorCode:BAD_DATA_FORMAT, parameter:Note.guid)
at com.evernote.edam.notestore.NoteStore$getNote_result.read(NoteStore.java:13514)
at com.evernote.edam.notestore.NoteStore$Client.recv_getNote(NoteStore.java:1346)
at com.evernote.edam.notestore.NoteStore$Client.getNote(NoteStore.java:1316)
at com.evernote.clients.NoteStoreClient.getNote(NoteStoreClient.java:368)
at com.journaldev.spring.service.EvernoteServiceImpl.findNoteById(EvernoteServiceImpl.java:157)
You can't set a manually assigned guid on a note when creating it - guids are assigned by the service and returned on the Note object as part of the createNote call on NoteStore.
As an aside, guids have a certain format, see the format here.
I established connection to a SAP Server and I would like to print a list of BAPIs in my Java program. I am using sapjco3.jar.
Is there any way to do it?
You can also use the function module SWO_QUERY_API_METHODS. The following code snippet works with JCo 2:
IFunctionTemplate functionTemplate = Repository.getFunctionTemplate("SWO_QUERY_API_METHODS");
JCO.Function function = functionTemplate.getFunction();
mConnection.execute(function);
ParameterList exportParameter = function.getExportParameterList();
System.out.println("exportParameter: " + exportParameter);
ParameterList importParameter = function.getImportParameterList();
System.out.println("importParameter: " + importParameter);
ParameterList tableParameter = function.getTableParameterList();
System.out.println("tableParameter: " + tableParameter);
As far as I know, there is no "BAPI to get a list of BAPIs", so this would be a non-trivial task. You could try to use RFC_FUNCTION_SEARCH to search for function modules named BAPI*, but that's not guaranteed to give you a) only official BAPIs and b) all of the official BAPIs...
You can use the BAPI_MONITOR_GETLIST to get a list of all BAPIs in your system together with meta data.
You could make an ABAP function searching for all RFC functions in table TFDIR, with FMODE ='R' (remote). However, This will give you all remote-callable function, not only BAPIs.
I'm looking at the AWS API and I can't seem to find a method to help me get info on an existing RDS database. I also tried to use a method that gets a list of all the RDS databases but failed at that too.
I looked at 2 methods and apparently they aren't what I'm looking for or I'm using them wrong.
Method 1:
I looked at ModifyDBInstanceRequest, to see if I could specify the name of an existing database and if I could query it for its properties (mysql version, storage size, etc.)
The following piece of code didn't do as I expected. ad-dash-test is an existing db in RDS. When I ran my code, it said the engine version is null, even though this is an existing db and I specified it by its DB Instance name.
ModifyDBInstanceRequest blah = new ModifyDBInstanceRequest("ad-dash-test");
System.out.println("the engine ver is " + blah.getEngineVersion());
Method 2:
I tried using the DescribeDBInstancesResult method but it looks like it's used for newly created RDS databases, not existing ones.
DescribeDBInstancesResult db = new DescribeDBInstancesResult();
List<DBInstance> list = db.getDBInstances();
System.out.println("list length = " + list.size());
The list length that returns is 0 and I have 8 RDS instances.
I didn't find any examples in Amazon's SDK for RDS and using my logic and the API docs didn't seem to help. Hopefully someone can point me in the right direction. Thanks in advance for your help.
In both of your methods, you are just building a Request object, and you are never sending the request to AWS.
Try the following in your second example:
// Instantiating rdsClient directly is deprecated, use AmazonRDSClientBuilder.
// AmazonRDSClient rdsClient = new AmazonRDSClient(/*add your credentials and the proper constructor overload*/);
AmazonRDS rdsClient = AmazonRDSClientBuilder.defaultClient();
DescribeDBInstancesRequest request = new DescribeDBInstancesRequest();
DescribeDBInstancesResult result = rdsClient.describeDBInstances(request);
List<DBInstance> list = result.getDBInstances();
System.out.println("list length = " + list.size());
An example for method 1 (for modifying your instance(s)) should be similar.
am using this connection string to connect to mysql from java:
jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8
is it possible to set the session variable in the string so that SET UNIQUE_CHECKS=0; would be executed upon connecting to server? the obvious
jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8&unique_checks=0
doesn't seem to work, based on the fact that
'jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8&unique_checks=blahblah`
doesn't generate any error.
Cheers!
How about using sessionVariables:
jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8&sessionVariables=unique_checks=0
Your question is thus more "How do I concat Strings in Java?" ?
If so, then just use the + operator:
int uniqueChecks = 0; // Assign session variable here.
String url = "jdbc:mysql://localhost:3306/db?unique_checks=" + uniqueChecks;
Alternatively you can also use String#format() wherein you can use the %d pattern to represent a decimal:
int uniqueChecks = 0; // Assign session variable here.
String url = String.format("jdbc:mysql://localhost:3306/db?unique_checks=%d", uniqueChecks);
You can use Statement.execute() to run pretty much every statement the DB understands, including such a SET-statement.
The advantage of using an URL parameter or a dedicated method is that the JDBC-driver is actually aware that the option was set and can react accordingly. This may or may not be useful or necessary for this particular option, but it's vital for other options (for example toggling autocommit with such a statement is a very bad idea).
BalusC, thanks for a reply! actually I need to do that in Talend etl tool(which itself is a java code generator) and the only line i can edit is the "jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8" string, which gets translated to this java code:
String url_tMysqlBulkExec_1 = "jdbc:mysql://"
+ "localhost" +
":"
+ "3306"
+ "/"
+ "db"
+ "?"
+ "noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8&unique_checks=0";
that's the limitation, sorry for not pointing that out earlier.
According to mysql docs, there is no possibility to set the unique_checks setting, i guess i need to look for other solution than URL parameters (Joachim, thanks for reminding me that these things are called "URL parameters" - help a lot while googling :)