Revision 7801
Added by Jing Tao over 11 years ago
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java | ||
---|---|---|
393 | 393 |
} |
394 | 394 |
} |
395 | 395 |
if(!solrDoc.isEmpty()) { |
396 |
UpdateResponse response = solrServer.add(solrDoc); |
|
397 |
solrServer.commit(); |
|
398 | 396 |
IndexEvent event = new IndexEvent(); |
399 |
event.setType(IndexEvent.SUCCESSINSERT); |
|
400 | 397 |
event.setDate(Calendar.getInstance().getTime()); |
401 | 398 |
Identifier pid = new Identifier(); |
402 | 399 |
pid.setValue(doc.getIdentifier()); |
403 | 400 |
event.setPid(pid); |
404 |
event.setDescription("Successfully insert the solr index for the id "+pid.getValue()); |
|
405 | 401 |
try { |
406 |
EventlogFactory.createIndexEventLog().write(event); |
|
407 |
} catch (Exception e) { |
|
408 |
log.error("SolrIndex.insertToIndex - IndexEventLog can't insert the solr doc to the solr server :"+e.getMessage()); |
|
402 |
UpdateResponse response = solrServer.add(solrDoc); |
|
403 |
solrServer.commit(); |
|
404 |
event.setType(IndexEvent.SUCCESSINSERT); |
|
405 |
event.setDescription("Successfully insert the solr index for the id "+pid.getValue()); |
|
406 |
try { |
|
407 |
EventlogFactory.createIndexEventLog().write(event); |
|
408 |
} catch (Exception e) { |
|
409 |
log.error("SolrIndex.insertToIndex - IndexEventLog can't insert the solr doc to the solr server :"+e.getMessage()); |
|
410 |
} |
|
411 |
} catch (SolrServerException e) { |
|
412 |
event.setType(IndexEvent.FAILUREINSERT); |
|
413 |
event.setDescription("Failed to insert the solr index for the id "+pid.getValue()+" since "+e.getMessage()); |
|
414 |
try { |
|
415 |
EventlogFactory.createIndexEventLog().write(event); |
|
416 |
} catch (Exception ee) { |
|
417 |
log.error("SolrIndex.insertToIndex - IndexEventLog can't insert the solr doc to the solr server :"+ee.getMessage()); |
|
418 |
} |
|
419 |
throw e; |
|
420 |
} catch (IOException e) { |
|
421 |
event.setType(IndexEvent.FAILUREINSERT); |
|
422 |
event.setDescription("Failed to insert the solr index for the id "+pid.getValue()+" since "+e.getMessage()); |
|
423 |
try { |
|
424 |
EventlogFactory.createIndexEventLog().write(event); |
|
425 |
} catch (Exception ee) { |
|
426 |
log.error("SolrIndex.insertToIndex - IndexEventLog can't insert the solr doc to the solr server :"+ee.getMessage()); |
|
427 |
} |
|
428 |
throw e; |
|
429 |
|
|
409 | 430 |
} |
410 |
|
|
411 | 431 |
//System.out.println("=================the response is:\n"+response.toString()); |
412 | 432 |
} |
413 | 433 |
} |
... | ... | |
604 | 624 |
*/ |
605 | 625 |
private void removeFromIndex(String pid) throws SolrServerException, IOException { |
606 | 626 |
if(pid != null && !pid.trim().equals("")) { |
607 |
solrServer.deleteById(pid); |
|
608 |
solrServer.commit(); |
|
609 | 627 |
IndexEvent event = new IndexEvent(); |
610 |
event.setType(IndexEvent.SUCCESSINSERT); |
|
611 | 628 |
event.setDate(Calendar.getInstance().getTime()); |
612 | 629 |
Identifier identifier = new Identifier(); |
613 | 630 |
identifier.setValue(pid); |
614 | 631 |
event.setPid(identifier); |
615 |
event.setDescription("Successfully remove the solr index for the id "+identifier.getValue()); |
|
616 | 632 |
try { |
617 |
EventlogFactory.createIndexEventLog().write(event); |
|
618 |
} catch (Exception e) { |
|
619 |
log.error("SolrIndex.insertToIndex - IndexEventLog can't insert the solr doc to the solr server :"+e.getMessage()); |
|
633 |
solrServer.deleteById(pid); |
|
634 |
solrServer.commit(); |
|
635 |
event.setType(IndexEvent.SUCCESSDELETE); |
|
636 |
event.setDescription("Successfully remove the solr index for the id "+identifier.getValue()); |
|
637 |
try { |
|
638 |
EventlogFactory.createIndexEventLog().write(event); |
|
639 |
} catch (Exception e) { |
|
640 |
log.error("SolrIndex.removeFromIndex - IndexEventLog can't insert the solr doc to the solr server :"+e.getMessage()); |
|
641 |
} |
|
642 |
} catch (SolrServerException e) { |
|
643 |
event.setType(IndexEvent.FAILUREDELETE); |
|
644 |
event.setDescription("Failurely remove the solr index for the id "+identifier.getValue()+" since "+e.getMessage()); |
|
645 |
try { |
|
646 |
EventlogFactory.createIndexEventLog().write(event); |
|
647 |
} catch (Exception ee) { |
|
648 |
log.error("SolrIndex.removeFromIndex - IndexEventLog can't insert the solr doc to the solr server :"+ee.getMessage()); |
|
649 |
} |
|
650 |
throw e; |
|
651 |
|
|
652 |
} catch (IOException e) { |
|
653 |
event.setType(IndexEvent.FAILUREDELETE); |
|
654 |
event.setDescription("Failurely remove the solr index for the id "+identifier.getValue()+" since "+e.getMessage()); |
|
655 |
try { |
|
656 |
EventlogFactory.createIndexEventLog().write(event); |
|
657 |
} catch (Exception ee) { |
|
658 |
log.error("SolrIndex.removeFromIndex - IndexEventLog can't insert the solr doc to the solr server :"+ee.getMessage()); |
|
659 |
} |
|
660 |
throw e; |
|
620 | 661 |
} |
662 |
|
|
621 | 663 |
} |
622 | 664 |
} |
623 | 665 |
|
Also available in: Unified diff
Add the code to log the failed events.