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);
}
}
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);
}
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;
}
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);
}
Aggregations