Error in Python when communicating with AWS - amazon-ec2

I have this code, am not sure why the security group is not recognized :
rs = client.get_all_security_groups()
print rs
SecurityGroup:default
req=client.request_spot_instances(price= 0.5,
image_id=config.get('EC2', 'ami'),
instance_type=config.get('EC2', 'type'),
key_name=config.get('EC2', 'key_pair'),
user_data='',
security_groups='default')[0]
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidParameterValue</Code>
<Message>
Value () for parameter groupId is invalid. The value cannot be empty</Message></Error></Errors>
<RequestID>a50166a5-3c30-4572-9474-ec46d6a978d0</RequestID></Response>
I

You need to set security group id, not security group name
rs = client.get_all_security_groups()
print rs
SecurityGroup:default
req=client.request_spot_instances(price= 0.5,
image_id=config.get('EC2', 'ami'),
instance_type=config.get('EC2', 'type'),
key_name=config.get('EC2', 'key_pair'),
user_data='',
security_groups=rs.id)[0]

Related

H2 show value of DB_CLOSE DELAY (set by SET DB_CLOSE_DELAY)

The H2 Database has a list of commands starting with SET, in particular SET DB_CLOSE_DELAY. I would like to find out what the value of DB_CLOSE_DELAY is. I am using JDBC. Setting is easy
cx.createStatement.execute("SET DB_CLOSE_DELAY 0")
but none of the following returns the actual value of DB_CLOSE_DELAY:
cx.createStatement.executeQuery("DB_CLOSE_DELAY")
cx.createStatement.executeQuery("VALUES(#DB_CLOSE_DELAY)")
cx.createStatement.executeQuery("GET DB_CLOSE_DELAY")
cx.createStatement.executeQuery("SHOW DB_CLOSE_DELAY")
Help would be greatly appreciated.
You can access this and other settings in the INFORMATION_SCHEMA.SETTINGS table - for example:
String url = "jdbc:h2:mem:;DB_CLOSE_DELAY=3";
Connection conn = DriverManager.getConnection(url, "sa", "the password goes here");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SETTINGS where name = 'DB_CLOSE_DELAY'");
while (rs.next()) {
System.out.println(rs.getString("name"));
System.out.println(rs.getString("value"));
}
In this test, I use an unnamed in-memory database, and I explicitly set the delay to 3 seconds when I create the DB.
The output from the print statements is:
DB_CLOSE_DELAY
3

when create note in evernote in evernote api, raise Evernote::EDAM::Error::EDAMUserException

here is my full code, following is my code:
note_store = c.note_store
note_title = ::Time.now.to_s
note_body = ::Time.now.to_s
n_body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
n_body += "<!DOCTYPE en-n SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
n_body += "<en-n>#{note_body}</en-n>"
## Create n object
our_note = Evernote::EDAM::Type::Note.new
our_note.title = note_title
our_note.content = n_body
I'm sure my developer token can work for search evernote notes, but when i create note, it raise this error
the full error is:
<Evernote::EDAM::Error::EDAMUserException errorCode:ENML_VALIDATION (11), parameter:"Element type \"en-n\" must be declared.">
see here, following code will work
note_store = c.note_store
note_title = ::Time.now.to_s
note_body = <<-CONTENT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>#{::Time.now}</en-note>
CONTENT
## Create n object
our_note = Evernote::EDAM::Type::Note.new
our_note.title = note_title
our_note.content = note_body;
you have to clear all files in c:\users\%username%\appdata\local\evernote or the equivalent in your OS environment.

Post large amount of data with Wicket.ajax.post

I'm trying to use the Behavior and JavaScript FileReader as can be seen in this question: Wicket Drag and drop functionality for adding an image
If I post more than 200k, I get an error Form too large. So perhaps I am missing some multipart stuff.
What is the proper way to call Wicket.ajax.post() with a large amount of data?
I tried setting mp to true, but then it started complaining that I do not have a form id. Does it need a form?
Btw. I use Jetty, but that has no problems using a regular file upload using forms.
This error comes from jetty Request implementation.
If you look at sources of the Request#extractFormParameters method, you will see next:
if (_context != null)
{
maxFormContentSize = _context.getContextHandler().getMaxFormContentSize();
maxFormKeys = _context.getContextHandler().getMaxFormKeys();
}
if (maxFormContentSize < 0)
{
Object obj = _channel.getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
if (obj == null)
maxFormContentSize = 200000;
else if
...
}
So, in fact, you can really set your context values as pikand proposed as 0, or set server config as follows:
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="setAttribute">
<Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
<Arg>-1<!-- or 0, or any lt 0 --></Arg>
</Call>
...
</Configure>
Your exception is thrown a bit later according to this code:
if (contentLength > maxFormContentSize && maxFormContentSize > 0)
{
throw new IllegalStateException("Form too large: " + contentLength + " > " + maxFormContentSize);
}
So, you can see, that maxFormContentSize could be <= 0 not to throw this exception.
I think, there is no need to update something via ajax. But in fact it is better to limit data size, not to allow users put down your server.
Other application servers have their own settings, for most of them you should set maxPostSize value to zero, to disable this restriction.
Also, wicket Form component has it's own maxSize property, you can set it with Form#setMaxSize. The problem is that Form transmittes this value as Bytes value to FileUploadBase class, which has next javadoc:
The maximum size permitted for the complete request, as opposed to
fileSizeMax. A value of -1 indicates no maximum.
And actually this parameter is set via fileUpload.setSizeMax(maxSize.bytes());, and Bytes can't hold negative value. But I think you can try to set it as 0 and check if it works. By default, Form#getSizeMax() method checks:
return getApplication().getApplicationSettings().getDefaultMaximumUploadSize();
Which returns Bytes.MAX, which is equals to 8388608 terabytes. I think, this is about to be "no limit" value :)
Additionaly, as I know - you don't need to set Form id, to allow using multipart parameter. Only if you updating your form via ajax, you have to set Form.setOutputMarkupId(true). But actually, Form creates id by itself in renderHead method if it is multipart:
// register some metadata so we can later properly handle multipart ajax posts for
// embedded forms
registerJavaScriptNamespaces(response);
response
.render(JavaScriptHeaderItem.forScript("Wicket.Forms[\"" + getMarkupId()
+ "\"]={multipart:true};", Form.class.getName() + '.' + getMarkupId()
+ ".metadata"));
Note, that getMarkupId() method creates markup id if does not exists.
There is a form size limit in Jetty defaulting to 200k.
Add a jetty-web.xml in your webapp/WEB-INF folder. There you can set a form size limit of the needed size.
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
<Configure id="WebAppContext" class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="maxFormContentSize" type="int">900000</Set>
<Set name="maxFormKeys">5000</Set>
</Configure>

WebSphere Portal: Update/Delete a War

I need to update a portlet on the WebSphere Portal 6.0. I have tried to use xmlaccess.bat. Here is my DeployPortlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<request
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="PortalConfig_1.4.xsd"
type="update"
create-oids="true">
<portal action="locate">
<!-- The uid must match uid attribute of portlet-app in portlet.xml. -->
<web-app action="update" active="true" uid="com.firstlinesoftware.oo.portlet.TestPortlet
<url>file:///$server_root$/installableApps/TestPortlet.war</url>
<!-- The uid must match uid attribute of concrete-portlet-app in portlet.xml. -->
<portlet-app action="update" active="true" uid="TestPortlet">
<!-- The name attribute must match content of portlet-name subtag of concrete-portlet in portlet.xml. -->
<portlet action="update" active="true" objectid="theIbmPortletApiPortlet" name="TestPortlet"/>
</portlet-app>
</web-app>
<!-- Parent element under which the new page is inserted -->
<content-node action="locate" objectid="parentPage" uniquename="ibm.portal.rational.portlets"/>
<!-- The new page.
The contentparentref attribute must match the objectid of the parent.
Change the uniquename attribute to create another page. -->
<content-node action="update" uniquename="ibm.portal.TestPortletPage" ordinal="last" content-parentref="parentPage" active="true" allportletsallowed="false" create-type="explicit" type="page">
<supported-markup markup="html" update="set"/>
<localedata locale="en"><title>TestPortletPage</title></localedata>
<component action="update" ordinal="100" type="container" orientation="H">
<component action="update" ordinal="100" type="control">
<!-- The portletref must match the objectid attribute of the portlet -->
<portletinstance action="update" portletref="theIbmPortletApiPortlet"/>
</component>
</component>
</content-node>
</portal>
When I use this script for the first time everything is ok. But when I try to update the portlet with this script (everywhere action="update") the exception occure: DuplicateAppException.
Then I have tried to delete this portlet via the script:
<?xml version="1.0" encoding="UTF-8"?>
<request
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="PortalConfig_1.4.xsd"
type="update"
create-oids="true">
<!-- sample for uninstalling a web module -->
<portal action="locate">
<!-- uid must match uid attribute of portlet-app in portlet.xml -->
<web-app action="delete" active="true" uid="TestPortlet">
</web-app>
</portal>
</request>
but the warning occure: Can't delete the portlet(there is no such a web module) maybe it was deleted earlier. Actually this war file is deployed (checked this with an administration console)
Can anybody, please, help me?
I typically don't do this using xmlaccess (couldn't tell you how). I redeploy the portlet application (war or ear depending on how you package it) as I would any application in WAS. Either through the admin console, or using wsadmin. It shouldn't be a problem for you to do it that way since portlet registrations are maintained over redeploys. Here is a sample jython script for deploying an app using wsadmin. It works both standalone and clustered (connect to the primary node).
import sys
import time
def wsadminToList(inStr):
outList=[]
if (len(inStr)>0 and inStr[0]=='[' and inStr[-1]==']'):
tmpList = inStr[1:-1].split() #splits space-separated lists,
else:
tmpList = inStr.split("\n") #splits for Windows or Linux
for item in tmpList:
item = item.rstrip(); #removes any Windows "\r"
if (len(item)>0):
outList.append(item)
return outList
#endDef
def installPortalApp(earFileName, appName, cellName, clusterName, installOptions):
#--------------------------------------------------------------
# set up globals
#--------------------------------------------------------------
global AdminApp
global AdminControl
global AdminConfig
global Help
installOptions.append('-appname')
installOptions.append(appName)
# Should we install on a cluster?
if len(clusterName) != 0:
appServer = 'WebSphere:cell=' + cellName + ',cluster=' + clusterName
mapModuleOptions = [[ '.*', '.*', appServer ]]
# Append additional options
installOptions.append('-cluster')
installOptions.append(clusterName)
AdminApp.install(earFileName, installOptions)
AdminConfig.save( )
count = 0
# This is probably not necessary
while not AdminApp.isAppReady(appName) and count < 10:
count = count + 1
print 'Waiting for app to be ready ' + count + ' of 10'
time.sleep(10)
#endWhile
clusterId = AdminConfig.getid('/ServerCluster:' + clusterName + '/' )
print 'clusterId' + clusterId
clusterMembers = wsadminToList(AdminConfig.list('ClusterMember', clusterId))
for member in clusterMembers:
print 'startApplication on member ' + str(member)
currentServer = AdminConfig.showAttribute(member, 'memberName')
print 'currentServer ' + currentServer
currentNodeName = AdminConfig.showAttribute(member, 'nodeName')
print 'currentNodeName ' + currentNodeName
query = 'cell=' + cellName + ',node=' + currentNodeName + ',type=ApplicationManager,process=' + currentServer + ',*'
print 'query ' + query
appMgr = AdminControl.queryNames(query )
print appMgr
Sync1 = AdminControl.completeObjectName('type=NodeSync,node=' + currentNodeName + ',*')
print 'Sync1 ' + Sync1
AdminControl.invoke(Sync1, 'sync')
print 'Node synchronized. Waiting a short while for binary expansion to finish'
time.sleep(5)
print 'Starting application'
AdminControl.invoke(appMgr, "startApplication", appName )
#endFor
else:
appMgr = AdminControl.queryNames("type=ApplicationManager,*" )
AdminApp.install(earFileName, installOptions)
AdminConfig.save( )
AdminControl.invoke(appMgr, "startApplication", appName )
#endIf
#endDef
#if (len(sys.argv) != 4 and len(sys.argv) != 5):
# print len(sys.argv)
# print "install_application_ear.py: this script requires the following parameters: ear file name, application name, cell name, install options and cluster name (optional)"
# sys.exit(1)
#endIf
earFileName = sys.argv[0]
print 'earFileName' + earFileName
appName = sys.argv[1]
cellName = sys.argv[2]
installOptions = eval(sys.argv[3])
clusterName = ""
if len(sys.argv) == 5:
clusterName = sys.argv[4]
installPortalApp(earFileName, appName, cellName, clusterName, installOptions)
Lets start from the end: the reason that your action=delete doesn't work is because you're referring to the webapp with an incorrect uid. During installation, you assign it the uid com.firstlinesoftware.oo.portlet.TestPortlet, and during deletion, you're referring to TestPortlet. That's not going to work out.
I programmed an automated system that redeploys portlet applications and it's been used for years with no issues, so something must be wrong in your XMLAccess file. Lets work through it. Can you start by removing the portlet-app child element altogether from the web-app element? is there a reason why you need it there?

VBScript Converting XML Data to an ADODB RecordSet

I have a situation in which I need to dump XML into an ADODB Recordset in VBScript. My XML is in the form below. What I would like to do in my code is convert the XML into a recordset with AddressObject rows. The code below I tried but keep running into one DomDocument error after another. Can anyone please help me with a solution for this? I tried the code below in Notepad++ but still unable to get the right result.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AuthorizationToken xmlns="http://www.avectra.com/2005/">
<Token>8d92d5ba-8b06-4464-9829-86eacac68e6c</Token>
</AuthorizationToken>
</soap:Header>
<soap:Body>
<GetQueryResponse xmlns="http://www.avectra.com/2005/">
<GetQueryResult>
<AddressObjects xsi:schemaLocation="http://www.avectra.com/2005/ Address.xsd" recordReturn="1">
<AddressObject>
<adr_key>2bbcd09f-89c7-4558-93bb-ce23e832ab94</adr_key>
<adr_line1>1447 Limerick Lane</adr_line1>
<adr_line2 xsi:nil="true" />
<adr_line3 xsi:nil="true" />
<adr_city>Canyon Lake</adr_city>
<adr_state>TX</adr_state>
<adr_post_code>78133</adr_post_code>
<adr_city_state_code>Canyon Lake, TX 78133</adr_city_state_code>
<adr_country>UNITED STATES</adr_country>
<adr_intl_province xsi:nil="true" />
<adr_county>Comal</adr_county>
<adr_bad_address_flag>0</adr_bad_address_flag>
<adr_no_validation_flag>0</adr_no_validation_flag>
<cst_id>001049008I</cst_id>
</AddressObject>
</AddressObjects>
</GetQueryResult>
</GetQueryResponse>
</soap:Body>
</soap:Envelope>
Public Function XMLToRecSet(Byref objXMLDoc2)
Dim rsReturn
Dim node
Dim attr ,attrs
Dim ObjXmlDoc
Set ObjXmlDoc = CreateObject("MSXML2.DOMDocument.3.0")
'Create/open the disconnected recordset
ObjXmlDoc = objXMLDoc2
Set node = objXMLDoc.selectSingleNode("//AddressObject/")
If( Not node Is Nothing) Then
Set rsReturn = CreateObject("ADODB.Recordset.6.0")
Set attrs = node.getAttributes()
for Each attr In attrs
rsReturn.Fields.Append attr.nodeName, adVarWChar, 255
Next
rsReturn.CursorLocation = adUseClient
rsReturn.CursorType = adOpenStatic
rsReturn.LockType = adLockOptimistic
rsReturn.Open
Set node = Nothing
'Loop/add rows
For Each node In objXMLDoc.selectNodes("//AddressObject/")
rsReturn.AddNew
For Each attr In node.Attributes
If(Not rsReturn(attr.nodeName)Is NOTHING) Then
rsReturn(attr.nodeName) = 1'attr.nodeValue
End if
Next
Next
If rsReturn.RecordCount <> 0 Then rsReturn.MoveFirst
'cExit:
End If
'Dispose DOM document
Set objXMLDoc = Nothing
Set XMLToRecSet = rsReturn
Set rsReturn = Nothing
End Function
Ado cannot handle an xml recordset. I think you need to use the old XML parser to get the data out. You could throw it into a db and then use ado to manipulate the data once its in a database.
Classic asp makes it very hard to work with Soap web services. I would strongly suggest coding this portion of your application in ASP.net ..

Resources