org.smartdeveloperhub.jenkins.crawler.AbstractCrawlingTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ci-jenkins-crawler Show documentation
Show all versions of ci-jenkins-crawler Show documentation
The Crawler for the Jenkins integration for the Continuous Integration Harvester of the Smart Developer Hub project
The newest version!
/**
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
* This file is part of the Smart Developer Hub Project:
* http://www.smartdeveloperhub.org/
*
* Center for Open Middleware
* http://www.centeropenmiddleware.com/
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
* Copyright (C) 2015-2016 Center for Open Middleware.
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
* Artifact : org.smartdeveloperhub.harvesters.ci.jenkins:ci-jenkins-crawler:0.3.0
* Bundle : ci-jenkins-crawler-0.3.0.jar
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
*/
package org.smartdeveloperhub.jenkins.crawler;
import static com.google.common.base.Preconditions.checkState;
import java.io.IOException;
import java.net.URI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartdeveloperhub.jenkins.JenkinsArtifactType;
import org.smartdeveloperhub.jenkins.JenkinsEntityType;
import org.smartdeveloperhub.jenkins.JenkinsResource;
import org.smartdeveloperhub.jenkins.Status;
import org.smartdeveloperhub.jenkins.client.JenkinsClientException;
import org.smartdeveloperhub.jenkins.client.JenkinsResourceProxy;
import org.smartdeveloperhub.jenkins.crawler.application.ModelMappingService;
import org.smartdeveloperhub.jenkins.crawler.application.spi.TransformationException;
import org.smartdeveloperhub.jenkins.crawler.event.JenkinsEvent;
import org.smartdeveloperhub.jenkins.crawler.xml.ci.Entity;
import org.smartdeveloperhub.jenkins.crawler.xml.ci.Instance;
import org.smartdeveloperhub.jenkins.crawler.xml.ci.Job;
import org.smartdeveloperhub.jenkins.crawler.xml.ci.Run;
import com.google.common.base.Optional;
abstract class AbstractCrawlingTask implements Task {
private static final int RETRY_THRESHOLD = 5;
private final Logger logger=LoggerFactory.getLogger(getClass()); // NOSONAR
private final URI location;
private final JenkinsEntityType entity;
private final JenkinsArtifactType artifact;
private Context context;
private int retries;
AbstractCrawlingTask(final URI location, final JenkinsEntityType entity, final JenkinsArtifactType artifact) {
this.location=location;
this.entity=entity;
this.artifact=artifact;
this.retries=0;
}
private void setContext(final Context context) {
this.context=context;
}
private JenkinsResourceProxy createProxy() {
JenkinsResourceProxy result = JenkinsResourceProxy.
create(this.location).
withEntity(this.entity);
final Optional depth=getDepth();
if(depth.isPresent()) {
result=result.withDepth(depth.get());
}
final Optional tree=getTree();
if(tree.isPresent()) {
result=result.withTree(tree.get());
}
final Optional wrapper=getWrapper();
if(wrapper.isPresent()) {
result=result.withWrapper(wrapper.get());
}
final Optional xpath=getXPath();
if(xpath.isPresent()) {
result=result.withXPath(xpath.get());
}
return result;
}
protected Optional getDepth() {
return Optional.absent();
}
protected Optional getTree() {
return Optional.absent();
}
protected Optional getWrapper() {
return Optional.absent();
}
protected Optional getXPath() {
return Optional.absent();
}
private void retryTask(final Throwable failure) {
this.retries++;
if(this.retries S entityOfId(final URI id, final JenkinsEntityType entityType, final Class extends S> entityClass) throws IOException {
checkState(this.context!=null);
return this.context.entityRepository().entityOfId(id,entityType,entityClass);
}
protected final ModelMappingService modelMapper() {
return this.context.modelMapper();
}
protected final CrawlingDecissionPoint crawlingDecissionPoint() {
checkState(this.context!=null);
return this.context.crawlingDecissionPoint();
}
protected final JenkinsInformationPoint jenkinsInformationPoint() {
checkState(this.context!=null);
return this.context.jenkinsInformationPoint();
}
protected final CrawlingSession currentCrawlingSession() {
checkState(this.context!=null);
return this.context.currentSession();
}
protected abstract String taskPrefix();
protected abstract void processResource(JenkinsResource resource) throws IOException;
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy