Search in sources :

Example 11 with OperationException

use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.

the class DebugRequest method getSessions.

/**
 * Experimental use only!
 */
@GET
@Path("/sessions")
@Produces({ "application/xml", "application/json" })
public Sessions getSessions(@Context HttpServletRequest request, @QueryParam("manager") final Long managerNum, @QueryParam("fields") final String fields, @Context @NotNull final BeanContext beanContext) {
    myDataProvider.checkGlobalPermission(Permission.MANAGE_SERVER_INSTALLATION);
    try {
        MBeanServer serverBean = ManagementFactory.getPlatformMBeanServer();
        Set<ObjectName> managerBeans = serverBean.queryNames(new ObjectName("Catalina:type=Manager,*"), null);
        if (managerBeans.isEmpty()) {
            throw new OperationException("No manager beans found. Not a Tomcat server or not a supported version of Tomcat?");
        }
        if (managerBeans.size() > 1 && managerNum == null) {
            throw new OperationException("Several manager beans found (" + managerBeans.size() + "). Specify '" + "manager" + "' query parameter with the 0-based number.");
        }
        final Iterator<ObjectName> it = managerBeans.iterator();
        if (managerNum != null) {
            for (int i = 0; i < managerNum; i++) {
                it.next();
            }
        }
        ObjectName managerBean = it.next();
        return new Sessions(serverBean, managerBean, new Fields(fields), beanContext);
    } catch (Exception e) {
        throw new OperationException("Could not get sessions data: " + e.toString(), e);
    }
}
Also used : Sessions(jetbrains.buildServer.server.rest.model.debug.Sessions) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 12 with OperationException

use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.

the class TagFinder method getPrefilteredItems.

@NotNull
@Override
public ItemHolder<TagData> getPrefilteredItems(@NotNull final Locator locator) {
    if (myBuildPromotion == null)
        throw new OperationException("Attempt to use the tags locator without setting build");
    final ArrayList<TagData> result = new ArrayList<TagData>(myBuildPromotion.getTagDatas());
    Collections.sort(result, new Comparator<TagData>() {

        public int compare(final TagData o1, final TagData o2) {
            if (o1 == o2)
                return 0;
            if (o1 == null)
                return -1;
            if (o2 == null)
                return 1;
            if (o1.isPublic()) {
                if (o2.isPublic()) {
                    return o1.getLabel().compareToIgnoreCase(o2.getLabel());
                }
                return -1;
            }
            if (o2.isPublic()) {
                return 1;
            }
            final SUser user1 = o1.getOwner();
            final SUser user2 = o2.getOwner();
            if (user1 == user2 || user1 == null || user2 == null)
                return o1.getLabel().compareToIgnoreCase(o2.getLabel());
            return user1.getUsername().compareToIgnoreCase(user2.getUsername());
        }
    });
    return getItemHolder(result);
}
Also used : SUser(jetbrains.buildServer.users.SUser) ArrayList(java.util.ArrayList) TagData(jetbrains.buildServer.serverSide.TagData) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with OperationException

use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.

the class TypedFinderBuilder method dimension.

public <TYPE> TypedFinderDimension<ITEM, TYPE> dimension(@NotNull final Dimension<TYPE> dimension, @NotNull final Type<TYPE> typeMapper) {
    // typeMapper: dimensionValue->typed object
    if (myDimensions.containsKey(dimension.name))
        throw new OperationException("Dimension with name '" + dimension.name + "' was already added");
    @NotNull TypedFinderDimensionImpl<TYPE> value = new TypedFinderDimensionImpl<>(dimension, typeMapper);
    myDimensions.put(dimension.name, value);
    return value;
}
Also used : NotNull(org.jetbrains.annotations.NotNull) OperationException(jetbrains.buildServer.server.rest.errors.OperationException)

Example 14 with OperationException

use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.

the class BeanFactory method create.

public <T> T create(Class<T> clazz, Object... params) {
    Class[] types = new Class[params.length];
    for (int i = 0; i < types.length; i++) {
        types[i] = params[i].getClass();
    }
    final Constructor<T> constructor = findConstructor(clazz, types);
    if (constructor == null) {
        throw new OperationException("Could not find constructor for class " + clazz.getName() + " with parameters " + describe(params));
    }
    final T t;
    try {
        t = constructor.newInstance(params);
    } catch (InstantiationException e) {
        throw new OperationException("Could not instantiate class " + clazz.getName() + " with parameters " + describe(params), e);
    } catch (IllegalAccessException e) {
        throw new OperationException("Could not instantiate class " + clazz.getName() + " with parameters " + describe(params), e);
    } catch (InvocationTargetException e) {
        throw new OperationException("Could not instantiate class " + clazz.getName() + " with parameters " + describe(params), e);
    }
    return autowire(t);
}
Also used : OperationException(jetbrains.buildServer.server.rest.errors.OperationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

OperationException (jetbrains.buildServer.server.rest.errors.OperationException)14 NotNull (org.jetbrains.annotations.NotNull)9 IOException (java.io.IOException)7 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)7 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)5 InputStream (java.io.InputStream)2 UnknownHostException (java.net.UnknownHostException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)2 XmlElement (javax.xml.bind.annotation.XmlElement)2 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)2 XmlType (javax.xml.bind.annotation.XmlType)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)2 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)2 SUser (jetbrains.buildServer.users.SUser)2 Stopwatch (com.google.common.base.Stopwatch)1 Logger (com.intellij.openapi.diagnostic.Logger)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1