jHipster: Search criteria "GreaterThan,LessThan" for date time - java

In my jHipster project I want to search row by datetime range.
The fragments of my code are:
product-inquiry-view.component.html
<div class="input-group date" id='datetimepicker'>
<input id="field_dateStart" #dateStart="ngbDatepicker" [(ngModel)]="criteriaByStartDate"/>
<input id="field_dateEnd" #dateEnd="ngbDatepicker" [(ngModel)]="criteriaByEndDate"/>
<button (click)="findByCriteria()"
</button>
</div>
Component class:
product-inquiry-view.component.ts
export class ProductInquiryViewComponent implements OnInit, OnDestroy {
criteriaByStartDate: string;
criteriaByEndDate: string;
..........
findByCriteria() {
criteriaByStartDate: Date;
criteriaByEndDate: Date;
let criteriaByStartDate = this.criteriaByStartDate;
let criteriaByEndDate = this.criteriaByEndDate
this.productInquiryViewService
.query({
'piDate.greaterThan': criteriaByStartDate,
'piDate.lessThan': criteriaByEndDate,
'piDocnum.contains': this.criteriaByDocnum
}).subscribe(
(res: HttpResponse<IProductInquiryView[]>) => {
this.productInquiryViews = res.body;
},
(res: HttpErrorResponse) => this.onError(res.message)
);
}
Controller:
ProductInquiryViewResource.java
#GetMapping("/product-inquiry-views")
#Timed
public ResponseEntity<List<ProductInquiryViewDTO>> getAllProductInquiryViews(ProductInquiryViewCriteria criteria) {
log.debug("REST request to get ProductInquiryViews by criteria: {}", criteria);
List<ProductInquiryViewDTO> entityList = productInquiryViewQueryService.findByCriteria(criteria);
return ResponseEntity.ok().body(entityList);
}
And I got exception:
2019-04-15 12:48:45.910 WARN 24330 --- [ XNIO-2 task-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.validation.BindException:
org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'productInquiryViewCriteria' on field 'piDate.greaterThan': rejected value [Mon Apr 01 2019 00:00:00 GMT 0300]; codes
[typeMismatch.productInquiryViewCriteria.piDate.greaterThan,typeMismatch.piDate.greaterThan,typeMismatch.greaterThan,typeMismatch.java.time.ZonedDateTime,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes [productInquiryViewCriteria.piDate.greaterThan,piDate.greaterThan]; arguments [];
default message [piDate.greaterThan]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.ZonedDateTime'
for property 'piDate.greaterThan'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String]
to type [java.time.ZonedDateTime] for value 'Mon Apr 01 2019 00:00:00 GMT 0300'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [Mon Apr 01 2019 00:00:00 GMT 0300]] enter code here
I see that "Mon Apr 01 2019 00:00:00 GMT 0300" is not correst string for parsing to ZoneDateTime, so I tried send criteria in such format :
"2019-04-01T00:15:30+03:00[Europe/Moscow]";
Same result.

Should be :
this.productInquiryViewService
.query({
'piDate.greaterThan': criteriaByStartDate.toISOString(),
'piDate.lessThan': criteriaByEndDate.toISOString(),
...

Related

Grails loosing time information of a Date when parsing JSON

My grails API is getting the time string but is loosing the seconds info.
I receive "16/02/2023 17:52:31" and results in a Date object with "16/02/2023 17:52:00"
class SampleObject {
static hasOne = [timeObject: TimeObject]
}
class TimeObject {
Date begin
Date end
static belongsTo = [sampleObject: SampleObject]
static constraints = {
begin nullable: true
end nullable: true
sampleObject nullable: false, unique: true
}
}
def controllerMethod() {
def bodyJSON = request.reader.text
def sampleObject = new SampleObject (JSON.parse(bodyJSON))
println sampleObject
}
In this sample above I send:
{
sampleObject: {
"begin": "16/02/2023 17:52:31",
"end": "16/02/2023 17:53:12"
}
}
Result:
begin= {Date#16875} "Thu Feb 16 17:52:00 BRT 2023"
end= {Date#16876} "Thu Feb 16 17:53:00 BRT 2023"
In my application.groovy I have:
grails.databinding.dateFormats = ['dd/MM/yyyy HH:mm', 'dd/MM/yyyy HH:mm:ss', 'yyyy-MM-dd HH:mm:ss.S', "yyyy-MM-dd'T'hh:mm:ss'Z'"]
PS: I'm using grails 3.1
The problem was in the "grails.databinding.dateFormats" order.
I solve changing to this:
grails.databinding.dateFormats = ['dd/MM/yyyy HH:mm:ss', 'dd/MM/yyyy HH:mm', 'yyyy-MM-dd HH:mm:ss.S', "yyyy-MM-dd'T'hh:mm:ss'Z'"]

how to convert blob to arraybuffer or string to blob

Imagine I have a file with this data:
lastModified: 1543877513859
lastModifiedDate: Tue Dec 04 2018 02:21:53 GMT+0330 (Iran Standard Time) {}
name: "ali.jpg"
objectURL: SafeUrlImpl
changingThisBreaksApplicationSecurity: "blob:http://localhost:4200/b45412e9-69ad-433f-b24d-b3833d705da4"
__proto__: SafeValueImpl
size: 16196
type: "image/jpeg"
webkitRelativePath: ""
So I want to get the binary data of this image. I read some info of how to get the content of image here. so I try to get the binary data with this:
const expecteadBinaryData= file.objectURL.
changingThisBreaksApplicationSecurity.arrayBuffer();
reader.onload = (e) => e.target.result;
const expecteadBinaryData2 =reader.readAsDataURL(new Blob
([file.objectURL.changingThisBreaksApplicationSecurity]));
So I expect the result of expecteadBinaryData or expecteadBinaryData2 be a binary, but I get undefined. How should I get this?

Pretty print String to JSON format

I execute an AWS command to retrieve the spot price history.
DescribeSpotPriceHistoryRequest request = new DescribeSpotPriceHistoryRequest().withEndTime(start)
.withInstanceTypes("m1.xlarge").withProductDescriptions("Linux/UNIX (Amazon VPC)").withStartTime(end);
DescribeSpotPriceHistoryResult response = client.describeSpotPriceHistory(request);
System.out.println(response.toString());
I obtained the result in json format but I receive it in String like:
{SpotPriceHistory: [{AvailabilityZone: us-east-1d,InstanceType: m1.xlarge,ProductDescription: Linux/UNIX,SpotPrice: 0.035000,Timestamp: Wed Nov 07 00:18:50 CET 2018}, {AvailabilityZone: us-east-1c,InstanceType: m1.xlarge,ProductDescription: Linux/UNIX,SpotPrice: 0.035000,Timestamp: Wed Nov 07 00:18:50 CET 2018}, {AvailabilityZone: us-east-1b,InstanceType: m1.xlarge,ProductDescription: Linux/UNIX,SpotPrice: 0.035000,Timestamp: Wed Nov 07 00:18:50 CET 2018}, {AvailabilityZone: us-east-1a,InstanceType: m1.xlarge,ProductDescription: Linux/UNIX,SpotPrice: 0.035000,Timestamp: Wed Nov 07 00:18:50 CET 2018}, {AvailabilityZone: us-east-1e,InstanceType: m1.xlarge,ProductDescription: Linux/UNIX,SpotPrice: 0.350000,Timestamp: Thu Sep 20 01:08:39 CEST 2018}]}
my question is: How can I improve the displaying of the results ? like
{
"Timestamp": "2018-09-08T17:07:14.000Z",
"AvailabilityZone": "us-east-1d",
"InstanceType": "p2.16xlarge",
"ProductDescription": "Linux/UNIX",
"SpotPrice": "4.320000"
},
{
"Timestamp": "2018-09-08T17:07:14.000Z",
"AvailabilityZone": "us-east-1c",
"InstanceType": "p2.16xlarge",
"ProductDescription": "Linux/UNIX",
"SpotPrice": "4.320000"
},
{
"Timestamp": "2018-09-08T17:07:14.000Z",
"AvailabilityZone": "us-east-1b",
"InstanceType": "p2.16xlarge",
"ProductDescription": "Linux/UNIX",
"SpotPrice": "4.320000"
},
{
"Timestamp": "2018-09-08T12:32:28.000Z",
"AvailabilityZone": "us-east-1e",
"InstanceType": "p2.16xlarge",
"ProductDescription": "Linux/UNIX",
"SpotPrice": "4.320000"
}
]
}
You're calling the .toString() on the response object, just be careful with this as there is no guarantee that will always be json, as you're seeing above, it's not even valid json as it's missing quotes around the attribute names and values.
One option to get what you want is to call response.getSpotPriceHistory() to get you the array of spot prices, then pass that thru ObjectMapper and write it as a pretty string, like so:
public static void main(String[] args) throws IOException {
AmazonEC2 client = AmazonEC2Client.builder().build();
DescribeSpotPriceHistoryRequest request = new DescribeSpotPriceHistoryRequest()
.withEndTime(new Date())
.withInstanceTypes("m1.xlarge").withProductDescriptions("Linux/UNIX (Amazon VPC)")
.withStartTime(new Date());
DescribeSpotPriceHistoryResult response = client.describeSpotPriceHistory(request);
ObjectMapper mapper = new ObjectMapper();
String asPrettyJSon = mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(response.getSpotPriceHistory());
System.out.println(asPrettyJSon);
}
Both represent a json array containing jsonObjects of same structure.
Displaying result will depend on your front implementation not the layaout of your jsonRespense.

Split grouped timestamped log data using timestamp itself as splitter?

I wanted to write code which could read a log file and split it into multiple events, using the timestamp as the splitter (since every log entry begins with a timestamp). A sample of the logs I want to split is given below. I'd also like to keep the timestamp itself.
So if this is my input:
01 Aug 2016 04:48:13,311 ERROR [pool-2-thread-12436] com.orders.queue.OrdersQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Exception while calling /purchases: x-company-status : UNKNOWN_ERROR response status: Internal Server Error
01 Aug 2016 04:48:13,311 WARN [pool-2-thread-12436] com.orders.queue.OrdersQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Failed to process order, will be re-tried: ADD2500051FR
01 Aug 2016 04:48:13,332 INFO [pool-2-thread-12436] com.delegate - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Getting Email from Primary email
01 Aug 2016 04:48:13,363 WARN [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Message processing failed QueueMessage [payload=ADD2500051FR, delaySeconds=0, sqsId=51f70e3f-554a-463b-8384-0b2c25a90450, stringAttributes={features=adac2911-0578-4bcd-b8c3-783481a48e1d, accept-language=FR_FR, request-id=836ac8b6-515d-4414-b4c6-ddd8a52ef497}]
com.orders.exception.orderserviceException: Error in Calling PUT purchase from main service
at com.OrderServiceDelegate.handleInternalServerErrors(OrderServiceDelegate.java:352)
at com.OrderServiceDelegate.sendOrderForProcessing_aroundBody0(OrderServiceDelegate.java:113)
at com.OrderServiceDelegate.sendOrderForProcessing_aroundBody1$advice(OrderServiceDelegate.java:37)
at com.OrderServiceDelegate.sendOrderForProcessing(OrderServiceDelegate.java:1)
at com.orders.queue.OrdersQueueWorker.doWork(OrdersQueueWorker.java:168)
at com.queue.SQSQueueWorker.lambda$0(SQSQueueWorker.java:149)
at com.queue.SQSQueueWorker.dt_access$492(SQSQueueWorker.java)
at com.queue.SQSQueueWorker$$dtt$$Lambda$8/852112146.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
01 Aug 2016 04:48:13,365 INFO [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Order will be re-tried after 300 seconds: ADD2500051FR
01 Aug 2016 04:48:15,600 INFO [myScheduler-3] com.queue.SQSQueueWorker - x-company-requestid=sqs-worker service_name=orders_v3 Processing messages message_number=1
01 Aug 2016 04:48:15,600 INFO [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Received msg from SQS:QueueMessage [payload=428CB476547214700268914651663, delaySeconds=0, sqsId=7f4dcbbe-90c4-4e56-b4ab-50332597b5d8, stringAttributes={features=FIS-JEM, accept-language=EN_US, request-id=a2c31da4-517f-40ec-8587-624f97393659}]
Then my output should be (the horizontal line depicts where one entry ends and another begins):
01 Aug 2016 04:48:13,311 ERROR [pool-2-thread-12436] com.orders.queue.OrdersQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Exception while calling /purchases: x-company-status : UNKNOWN_ERROR response status: Internal Server Error
//--------------------------------------------
01 Aug 2016 04:48:13,311 WARN [pool-2-thread-12436] com.orders.queue.OrdersQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Failed to process order, will be re-tried: ADD2500051FR
//--------------------------------------------
01 Aug 2016 04:48:13,332 INFO [pool-2-thread-12436] com.delegate - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Getting Email from Primary email
//--------------------------------------------
01 Aug 2016 04:48:13,363 WARN [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Message processing failed QueueMessage [payload=ADD2500051FR, delaySeconds=0, sqsId=51f70e3f-554a-463b-8384-0b2c25a90450, stringAttributes={features=adac2911-0578-4bcd-b8c3-783481a48e1d, accept-language=FR_FR, request-id=836ac8b6-515d-4414-b4c6-ddd8a52ef497}]
com.orders.exception.orderserviceException: Error in Calling PUT purchase from main service
at com.OrderServiceDelegate.handleInternalServerErrors(OrderServiceDelegate.java:352)
at com.OrderServiceDelegate.sendOrderForProcessing_aroundBody0(OrderServiceDelegate.java:113)
at com.OrderServiceDelegate.sendOrderForProcessing_aroundBody1$advice(OrderServiceDelegate.java:37)
at com.OrderServiceDelegate.sendOrderForProcessing(OrderServiceDelegate.java:1)
at com.orders.queue.OrdersQueueWorker.doWork(OrdersQueueWorker.java:168)
at com.queue.SQSQueueWorker.lambda$0(SQSQueueWorker.java:149)
at com.queue.SQSQueueWorker.dt_access$492(SQSQueueWorker.java)
at com.queue.SQSQueueWorker$$dtt$$Lambda$8/852112146.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
//--------------------------------------------
01 Aug 2016 04:48:13,365 INFO [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Order will be re-tried after 300 seconds: ADD2500051FR
//--------------------------------------------
01 Aug 2016 04:48:15,600 INFO [myScheduler-3] com.queue.SQSQueueWorker - x-company-requestid=sqs-worker service_name=orders_v3 Processing messages message_number=1
//--------------------------------------------
01 Aug 2016 04:48:15,600 INFO [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Received msg from SQS:QueueMessage [payload=428CB476547214700268914651663, delaySeconds=0, sqsId=7f4dcbbe-90c4-4e56-b4ab-50332597b5d8, stringAttributes={features=FIS-JEM, accept-language=EN_US, request-id=a2c31da4-517f-40ec-8587-624f97393659}]
I imagine some sort of regex would be needed, but I have no experience in using regex to do such a split through Java code.
I also found the following related question, but I didn't understand the solution suggested there:
java regex: capture multiline sequence between tokens
The following code uses the log you supplied and produces your desired output. I've included comments in the code that explain the program flow.
Code:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Pattern;
public class Driver {
private static final String LINE_BREAK = System.lineSeparator();
// path to the logfile
private static final String LOG_FILE = "xin/xin.log";
// The regex below matches lines that begin with "00 Mth 0000 00:00:00,000".
private static Pattern pattern = Pattern.compile("^[0-9][0-9]\\s[A-Z][a-z][a-z]\\s[0-9][0-9][0-9][0-9]\\s[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9]");
public static void main(String[] args) {
BufferedReader reader = null;
StringBuilder sb = new StringBuilder();
String line = "";
boolean firstRun = true;
try {
// instantiated the buffered reader
reader = new BufferedReader(new FileReader(new File(LOG_FILE)));
} catch(FileNotFoundException e) {
e.printStackTrace();
}
// loop until all lines are read from log file
while(true) {
try {
// get next line from log file
line = reader.readLine();
// if no more content in log file then break out of loop
if(line == null) {
break;
}
} catch (IOException e) {
e.printStackTrace();
}
// we don't want a line-break before the first line
if(firstRun) {
firstRun = false;
// append the first line to the string builder
sb.append(line);
} else {
// we've handled the first line, so now we
// append a line-break to the string builder
// before appending the next line
sb.append(LINE_BREAK);
// if the line matches the timestamp pattern then
// append another line-break
if(pattern.matcher(line).find()) {
sb.append(LINE_BREAK);
}
// add the line to the string builder
sb.append(line);
}
}
try {
// close the buffered reader
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
// print string builder contents to standard out
System.out.println(sb.toString());
}
}
Output:
01 Aug 2016 04:48:13,311 ERROR [pool-2-thread-12436] com.orders.queue.OrdersQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Exception while calling /purchases: x-company-status : UNKNOWN_ERROR response status: Internal Server Error
01 Aug 2016 04:48:13,311 WARN [pool-2-thread-12436] com.orders.queue.OrdersQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Failed to process order, will be re-tried: ADD2500051FR
01 Aug 2016 04:48:13,332 INFO [pool-2-thread-12436] com.delegate - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Getting Email from Primary email
01 Aug 2016 04:48:13,363 WARN [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Message processing failed QueueMessage [payload=ADD2500051FR, delaySeconds=0, sqsId=51f70e3f-554a-463b-8384-0b2c25a90450, stringAttributes={features=adac2911-0578-4bcd-b8c3-783481a48e1d, accept-language=FR_FR, request-id=836ac8b6-515d-4414-b4c6-ddd8a52ef497}]
com.orders.exception.orderserviceException: Error in Calling PUT purchase from main service
at com.OrderServiceDelegate.handleInternalServerErrors(OrderServiceDelegate.java:352)
at com.OrderServiceDelegate.sendOrderForProcessing_aroundBody0(OrderServiceDelegate.java:113)
at com.OrderServiceDelegate.sendOrderForProcessing_aroundBody1$advice(OrderServiceDelegate.java:37)
at com.OrderServiceDelegate.sendOrderForProcessing(OrderServiceDelegate.java:1)
at com.orders.queue.OrdersQueueWorker.doWork(OrdersQueueWorker.java:168)
at com.queue.SQSQueueWorker.lambda$0(SQSQueueWorker.java:149)
at com.queue.SQSQueueWorker.dt_access$492(SQSQueueWorker.java)
at com.queue.SQSQueueWorker$$dtt$$Lambda$8/852112146.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
01 Aug 2016 04:48:13,365 INFO [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Order will be re-tried after 300 seconds: ADD2500051FR
01 Aug 2016 04:48:15,600 INFO [myScheduler-3] com.queue.SQSQueueWorker - x-company-requestid=sqs-worker service_name=orders_v3 Processing messages message_number=1
01 Aug 2016 04:48:15,600 INFO [pool-2-thread-12436] com.queue.SQSQueueWorker - x-company-requestid=836ac8b6-515d-4414-b4c6-ddd8a52ef497-sqs service_name=orders_v3 Received msg from SQS:QueueMessage [payload=428CB476547214700268914651663, delaySeconds=0, sqsId=7f4dcbbe-90c4-4e56-b4ab-50332597b5d8, stringAttributes={features=FIS-JEM, accept-language=EN_US, request-id=a2c31da4-517f-40ec-8587-624f97393659}]
If you need any additional help, then just leave a comment on this answer and I'll try my best to help.

MongoDb Mass Saving "isOK() checkWriteError" Exception

I'm trying to write a parser and and I'm using MongoDB as a database. Essentially it is going through, creating objects, and then saving them. It is doing this several times a second. After around 164 objects are saved it crashes with this error:
com.mongodb.MongoException: isOk() at
com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:130)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:142) at
com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:141) at
com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:97) at
com.mongodb.DBCollection.insert(DBCollection.java:61) at
com.mongodb.DBCollection.save(DBCollection.java:547) at
com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:638) at
com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:685) at
com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:679) at
com.soleo.internal.releasenotes.orm.Storage.save(Storage.java:764) at
com.soleo.internal.releasenotes.page.MainPage$2.onSubmit(MainPage.java:256)
Now at one point I had over 1000 objects in this same database, I just didn't insert them all at once. So it can't be a hard drive space issue. I can't find any documentation at all of this error online. Oddly it's only when I try saving THIS object. If I try saving Object B after the crash it saves just fine. It just crashes on Object A, the one I initially mass saved.
I ran a test multiple times and it failed in the same place. I used random values so I could prove it wasn't a variable issue:
FIRST TRY:
==============================
CREATING RELEASE #162
Component: iHateYou
Location: 250344
Version: 8.8.1.5-2
Date: Sun Feb 07 00:00:00 EST 3188 (02-07-3188)
SAVING.............
SUCCESS.
==============================
CREATING RELEASE #163
Component: iHateYou
Location: 227407
Version: 5.5.7.6-7
Date: Sat Mar 04 00:00:00 EST 439 (03-04-439)
SAVING.............
SUCCESS.
==============================
CREATING RELEASE #164
Component: iHateYou
Location: 38694
Version: 3.5.4.7-7
Date: Mon Jan 03 00:00:00 EST 158 (01-03-158)
SAVING.............
Oct 28, 2011 11:17:11 AM org.apache.wicket.RequestCycle logRuntimeException
SEVERE: isOk()
com.mongodb.MongoException: isOk()
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:130)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:142)
SECOND TRY:
==============================
CREATING RELEASE #162
Component: iHateYou
Location: 64717
Version: 0.1.0.4-8
Date: Sun May 07 00:00:00 EST 971 (05-07-971)
SAVING.............
SUCCESS.
==============================
CREATING RELEASE #163
Component: iHateYou
Location: 19360
Version: 4.5.8.1-3
Date: Wed Aug 04 00:00:00 EST 1339 (08-04-1339)
SAVING.............
SUCCESS.
==============================
CREATING RELEASE #164
Component: iHateYou
Location: 115518
Version: 0.0.8.0-2
Date: Sat Apr 07 00:00:00 EST 143 (04-07-143)
SAVING.............
Oct 28, 2011 11:15:28 AM org.apache.wicket.RequestCycle logRuntimeException
SEVERE: isOk()
com.mongodb.MongoException: isOk()
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:130)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:142)
Here's some partially obfuscated code:
Random blank = new Random();
ObjectRef blah = new ObjectRef("iHateYou");
storage.save(blah);
for(int i = 0; i < 300; i++)
{
System.out.println("==============================\nCREATING OBJECT #" + i);
ObjectA saveMe = new ObjectA();
saveMe.setRef(storage.getRefByName("iHateYou"));
System.out.println("Component: " + saveMe.getRef.getName());
saveMe.setLocation(blank.nextInt(300000) + "");
System.out.println("Location: " + saveMe.getLocation());
saveMe.setVersion(new Version(blank.nextInt(9) + "." + blank.nextInt(9) + "." + blank.nextInt(9) + "." + blank.nextInt(9) + "-" + blank.nextInt(9)));
System.out.println("Version: " + saveMe.getVersion());
try
{
String randomDate = "0" + blank.nextInt(9) + "-0" + blank.nextInt(9) + "-" + blank.nextInt(4000);
saveMe.setReleaseDate(new SimpleDateFormat("MM-dd-yyyy").parse(randomDate));
System.out.println("Date: " + saveMe.getReleaseDate() + " (" + randomDate + ") ");
}
catch (ParseException e)
{
e.printStackTrace();
}
System.out.println("SAVING.............");
storage.save(saveMe);
System.out.println("SUCCESS.");
}
Sounds like it could be a variation of this bug: https://jira.mongodb.org/browse/RUBY-324
Are you using sharding? In that case your config DB might be corrupt. The driver is probably not expecting to receive the message "isOk" back.
Please tell us more about your environment: MongoDB version, using sharding or not, driver version, etc.

Categories