use of org.apache.sling.api.resource.LoginException in project sling by apache.
the class HeartbeatHandler method doCheckView.
/** Check whether the established view matches the reality, ie matches the
* heartbeats
*/
@Override
protected void doCheckView() {
super.doCheckView();
ResourceResolver resourceResolver = null;
try {
resourceResolver = getResourceResolver();
doCheckViewWith(resourceResolver);
} catch (LoginException e) {
logger.error("checkView: could not log in administratively: " + e, e);
} catch (PersistenceException e) {
logger.error("checkView: encountered a persistence exception during view check: " + e, e);
} catch (RuntimeException e) {
logger.error("checkView: encountered a runtime exception during view check: " + e, e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
use of org.apache.sling.api.resource.LoginException in project sling by apache.
the class HeartbeatHandler method resetLeaderElectionId.
/**
* Hook that will cause a reset of the leaderElectionId
* on next invocation of issueClusterLocalHeartbeat.
* @return true if the leaderElectionId was reset - false if that was not
* necessary as that happened earlier already and it has not propagated
* yet to the ./clusterInstances in the meantime
*/
public boolean resetLeaderElectionId() {
if (resetLeaderElectionId) {
// resetting twice doesn't work
return false;
}
resetLeaderElectionId = true;
ResourceResolver resourceResolver = null;
try {
resourceResolver = getResourceResolver();
if (resourceResolver != null) {
newLeaderElectionId = newLeaderElectionId(resourceResolver);
if (votingHandler != null) {
logger.info("resetLeaderElectionId: set new leaderElectionId with votingHandler to: " + newLeaderElectionId);
votingHandler.setLeaderElectionId(newLeaderElectionId);
} else {
logger.info("resetLeaderElectionId: no votingHandler, new leaderElectionId would be: " + newLeaderElectionId);
}
} else {
logger.warn("resetLeaderElectionId: could not login, new leaderElectionId will be calculated upon next heartbeat only!");
}
} catch (LoginException e) {
logger.error("resetLeaderElectionid: could not login: " + e, e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
return true;
}
use of org.apache.sling.api.resource.LoginException in project sling by apache.
the class DiscoveryServiceImpl method doUpdateProperties.
/**
* Update the properties by inquiring the PropertyProvider's current values.
* <p>
* This method is invoked regularly by the heartbeatHandler.
* The properties are stored in the repository under Config.getClusterInstancesPath()
* and announced in the topology.
* <p>
* @see Config#getClusterInstancesPath()
*/
private void doUpdateProperties() {
if (resourceResolverFactory == null) {
// cannot update the properties then..
logger.debug("doUpdateProperties: too early to update the properties. resourceResolverFactory not yet set.");
return;
} else {
logger.debug("doUpdateProperties: updating properties now..");
}
final Map<String, String> newProps = new HashMap<String, String>();
for (final ProviderInfo info : this.providerInfos) {
info.refreshProperties();
newProps.putAll(info.properties);
}
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory.getServiceResourceResolver(null);
Resource myInstance = ResourceHelper.getOrCreateResource(resourceResolver, config.getClusterInstancesPath() + "/" + slingId + "/properties");
// SLING-2879 - revert/refresh resourceResolver here to work
// around a potential issue with jackrabbit in a clustered environment
resourceResolver.revert();
resourceResolver.refresh();
final ModifiableValueMap myInstanceMap = myInstance.adaptTo(ModifiableValueMap.class);
final Set<String> keys = new HashSet<String>(myInstanceMap.keySet());
for (final String key : keys) {
if (newProps.containsKey(key)) {
// perfect
continue;
} else if (key.indexOf(":") != -1) {
// ignore
continue;
} else {
// remove
myInstanceMap.remove(key);
}
}
boolean anyChanges = false;
for (final Entry<String, String> entry : newProps.entrySet()) {
Object existingValue = myInstanceMap.get(entry.getKey());
if (entry.getValue().equals(existingValue)) {
// SLING-3389: dont rewrite the properties if nothing changed!
if (logger.isDebugEnabled()) {
logger.debug("doUpdateProperties: unchanged: {}={}", entry.getKey(), entry.getValue());
}
continue;
}
if (logger.isDebugEnabled()) {
logger.debug("doUpdateProperties: changed: {}={}", entry.getKey(), entry.getValue());
}
anyChanges = true;
myInstanceMap.put(entry.getKey(), entry.getValue());
}
if (anyChanges) {
resourceResolver.commit();
}
} catch (LoginException e) {
logger.error("handleEvent: could not log in administratively: " + e, e);
throw new RuntimeException("Could not log in to repository (" + e + ")", e);
} catch (PersistenceException e) {
logger.error("handleEvent: got a PersistenceException: " + e, e);
throw new RuntimeException("Exception while talking to repository (" + e + ")", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
logger.debug("doUpdateProperties: updating properties done.");
}
use of org.apache.sling.api.resource.LoginException in project sling by apache.
the class JobManagerConfiguration method createResourceResolver.
/**
* Create a new resource resolver for reading and writing the resource tree.
* The resolver needs to be closed by the client.
* @return A resource resolver or {@code null} if the component is already deactivated.
* @throws RuntimeException if the resolver can't be created.
*/
public ResourceResolver createResourceResolver() {
ResourceResolver resolver = null;
final ResourceResolverFactory factory = this.resourceResolverFactory;
if (factory != null) {
try {
resolver = this.resourceResolverFactory.getServiceResourceResolver(null);
} catch (final LoginException le) {
logger.error("Unable to create new resource resolver: " + le.getMessage(), le);
throw new RuntimeException(le);
}
}
return resolver;
}
use of org.apache.sling.api.resource.LoginException in project sling by apache.
the class AbstractJobHandlingTest method cleanup.
public void cleanup() {
// clean job area
final ServiceReference<ResourceResolverFactory> ref = this.bc.getServiceReference(ResourceResolverFactory.class);
final ResourceResolverFactory factory = this.bc.getService(ref);
ResourceResolver resolver = null;
try {
resolver = factory.getAdministrativeResourceResolver(null);
final Resource rsrc = resolver.getResource("/var/eventing");
if (rsrc != null) {
delete(rsrc);
resolver.commit();
}
} catch (final LoginException le) {
// ignore
} catch (final PersistenceException e) {
// ignore
} catch (final Exception e) {
// sometimes an NPE is thrown from the repository, as we
// are in the cleanup, we can ignore this
} finally {
if (resolver != null) {
resolver.close();
}
}
// unregister all services
for (final ServiceRegistration<?> reg : this.registrations) {
reg.unregister();
}
this.registrations.clear();
// remove all configurations
try {
final org.osgi.service.cm.Configuration[] cfgs = this.configAdmin.listConfigurations(null);
if (cfgs != null) {
for (final org.osgi.service.cm.Configuration c : cfgs) {
try {
c.delete();
} catch (final IOException io) {
// ignore
}
}
}
} catch (final IOException io) {
// ignore
} catch (final InvalidSyntaxException e) {
// ignore
}
this.sleep(1000);
}
Aggregations