use of org.osgi.framework.InvalidSyntaxException in project stanbol by apache.
the class SolrYardComponent method initManagedSolrIndex.
/**
* initialise ManagedSolrIndex and that starts tracking for the {@link SolrCore}
* @param managedServer the managedServer to init the SolrCore (if necessary)
* @param config the {@link SolrYardConfig}
* @throws IllegalStateException if the initialization fails
*/
private void initManagedSolrIndex(final ManagedSolrServer managedServer, final SolrYardConfig config) {
if (managedServer == null || config == null) {
//component was not yet activated ... will be called again
return;
}
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
if (config.isAllowInitialisation()) {
//are we allowed to create the SolrServer
//get the name of the config to be used (default: default.solrindex.zip")
String configName = config.getIndexConfigurationName();
IndexMetadata metadata = managedServer.getIndexMetadata(solrIndexRef.getIndex());
if (metadata == null) {
//create a new index
log.info(" ... creating Managed SolrIndex {} (configName: {}) on Server {}", new Object[] { solrIndexRef.getIndex(), configName, managedServer.getServerName() });
try {
metadata = managedServer.createSolrIndex(solrIndexRef.getIndex(), configName, null);
} catch (IOException e) {
throw new IllegalStateException("Unable to create Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
}
} else if (metadata.getState() != ManagedIndexState.ACTIVE) {
log.info(" ... activating Managed SolrIndex {} on Server {} (current state: {})", new Object[] { solrIndexRef.getIndex(), managedServer.getServerName(), metadata.getState() });
try {
managedServer.activateIndex(metadata.getIndexName());
} catch (IOException e) {
throw new IllegalStateException("Unable to activate Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
} catch (SAXException e) {
throw new IllegalStateException("Unable to activate Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
}
}
//else already active nothing todo
solrIndexRef = metadata.getIndexReference();
}
//else the SolrServer will be supplied (e.g. created by installing a full index)
try {
registeredServerTracker = new RegisteredSolrServerTracker(context, solrIndexRef, null) {
@Override
public void removedService(ServiceReference reference, Object service) {
updateSolrYardRegistration(registeredServerTracker.getService(), config);
super.removedService(reference, service);
}
@Override
public void modifiedService(ServiceReference reference, Object service) {
updateSolrYardRegistration(registeredServerTracker.getService(), config);
super.modifiedService(reference, service);
}
@Override
public SolrServer addingService(ServiceReference reference) {
SolrServer server = super.addingService(reference);
if (solrServer != null) {
log.warn("Multiple SolrServer for IndexLocation {} available!", config.getSolrServerLocation());
} else {
updateSolrYardRegistration(server, config);
}
return server;
}
};
log.info(" ... start tracking for SolrCore based on {}", solrIndexRef);
//start tracking
registeredServerTracker.open();
} catch (InvalidSyntaxException e) {
throw new IllegalStateException("Unable to track Managed SolrIndex " + solrIndexRef.getIndex() + "on Server " + managedServer.getServerName() + "!", e);
}
}
use of org.osgi.framework.InvalidSyntaxException in project ddf by codice.
the class SourceConfigurationHandler method regenerateOneSource.
@Override
public void regenerateOneSource(String registryId) throws FederationAdminException {
try {
List<Metacard> metacards = federationAdminService.getRegistryMetacardsByRegistryIds(Collections.singletonList(registryId));
if (metacards.size() != 1) {
throw new FederationAdminException("Error looking up metacard to regenerate sources. registry-id=" + registryId);
}
deleteRegistryConfigurations(metacards.get(0));
updateRegistryConfigurations(metacards.get(0), true);
} catch (IOException | ParserException | InvalidSyntaxException e) {
throw new FederationAdminException("Error regenerating sources for registry entry " + registryId, e);
}
}
use of org.osgi.framework.InvalidSyntaxException in project ddf by codice.
the class RESTEndpoint method generateMetacard.
private Metacard generateMetacard(MimeType mimeType, String id, InputStream message, String transformerId) throws MetacardCreationException {
Metacard generatedMetacard = null;
List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType);
List<String> stackTraceList = new ArrayList<>();
LOGGER.trace("Entering generateMetacard.");
LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates);
try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
try {
if (null != message) {
IOUtils.copy(message, fileBackedOutputStream);
} else {
throw new MetacardCreationException("Could not copy bytes of content message. Message was NULL.");
}
} catch (IOException e) {
throw new MetacardCreationException("Could not copy bytes of content message.", e);
}
Iterator<InputTransformer> it = listOfCandidates.iterator();
if (StringUtils.isNotEmpty(transformerId)) {
BundleContext bundleContext = getBundleContext();
Collection<ServiceReference<InputTransformer>> serviceReferences = bundleContext.getServiceReferences(InputTransformer.class, "(id=" + transformerId + ")");
it = serviceReferences.stream().map(bundleContext::getService).iterator();
}
while (it.hasNext()) {
InputTransformer transformer = it.next();
try (InputStream inputStreamMessageCopy = fileBackedOutputStream.asByteSource().openStream()) {
generatedMetacard = transformer.transform(inputStreamMessageCopy);
} catch (CatalogTransformerException | IOException e) {
List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e));
stackTraceList.add(String.format("Transformer [%s] could not create metacard.", transformer));
stackTraceList.addAll(stackTraces);
LOGGER.debug("Transformer [{}] could not create metacard.", transformer, e);
}
if (generatedMetacard != null) {
break;
}
}
if (generatedMetacard == null) {
throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeType, StringUtils.join(stackTraceList, "\n")));
}
if (id != null) {
generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id));
} else {
LOGGER.debug("Metacard had a null id");
}
} catch (IOException e) {
throw new MetacardCreationException("Could not create metacard.", e);
} catch (InvalidSyntaxException e) {
throw new MetacardCreationException("Could not determine transformer", e);
}
return generatedMetacard;
}
use of org.osgi.framework.InvalidSyntaxException in project ddf by codice.
the class TestCswSourceBase method setUp.
@Before
public void setUp() {
ServiceReference ref = mock(ServiceReference.class);
ServiceReference[] serviceRefs = new ServiceReference[] { ref };
try {
when(mockContext.getServiceReferences(eq(MetadataTransformer.class.getName()), anyString())).thenReturn(serviceRefs);
when(mockContext.getServiceReferences(eq(STSClientConfiguration.class.getName()), anyString())).thenReturn(null);
} catch (InvalidSyntaxException e) {
LOGGER.error(e.getMessage(), e);
}
MetadataTransformer transformer = mock(MetadataTransformer.class);
// Just return same Metacard that was passed in
when(mockContext.getService(any(ServiceReference.class))).thenReturn(transformer);
try {
when(transformer.transform(any(Metacard.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
} catch (CatalogTransformerException e) {
LOGGER.error(e.getMessage(), e);
}
when(mockAvailabilityTask.isAvailable()).thenReturn(true);
}
use of org.osgi.framework.InvalidSyntaxException in project ddf by codice.
the class DumpCommand method getTransformers.
private List<MetacardTransformer> getTransformers() {
ServiceReference[] refs = null;
try {
refs = bundleContext.getAllServiceReferences(MetacardTransformer.class.getName(), "(|" + "(" + Constants.SERVICE_ID + "=" + transformerId + ")" + ")");
} catch (InvalidSyntaxException e) {
console.printf("Fail to get MetacardTransformer references due to %s", e.getMessage());
}
if (refs == null || refs.length == 0) {
return null;
}
List<MetacardTransformer> metacardTransformerList = new ArrayList<>();
for (ServiceReference ref : refs) {
metacardTransformerList.add((MetacardTransformer) bundleContext.getService(ref));
}
return metacardTransformerList;
}
Aggregations